Skip to content

Commit

Permalink
✨ Switch to TimeProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontaylordev committed Aug 6, 2023
1 parent 5a345d1 commit 4c06837
Show file tree
Hide file tree
Showing 14 changed files with 1,977 additions and 2,003 deletions.
6 changes: 0 additions & 6 deletions src/Application/Common/Interfaces/IDateTime.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Domain/Common/BaseAuditableEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

public abstract class BaseAuditableEntity : BaseEntity
{
public DateTime Created { get; set; }
public DateTimeOffset Created { get; set; }

public string? CreatedBy { get; set; }

public DateTime? LastModified { get; set; }
public DateTimeOffset LastModified { get; set; }

public string? LastModifiedBy { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace CleanArchitecture.Infrastructure.Data.Interceptors;
public class AuditableEntityInterceptor : SaveChangesInterceptor
{
private readonly IUser _user;
private readonly IDateTime _dateTime;
private readonly TimeProvider _dateTime;

public AuditableEntityInterceptor(
IUser user,
IDateTime dateTime)
TimeProvider dateTime)
{
_user = user;
_dateTime = dateTime;
Expand Down Expand Up @@ -42,13 +42,13 @@ public void UpdateEntities(DbContext? context)
if (entry.State == EntityState.Added)
{
entry.Entity.CreatedBy = _user.Id;
entry.Entity.Created = _dateTime.Now;
entry.Entity.Created = _dateTime.GetUtcNow();
}

if (entry.State == EntityState.Added || entry.State == EntityState.Modified || entry.HasChangedOwnedEntities())
{
entry.Entity.LastModifiedBy = _user.Id;
entry.Entity.LastModified = _dateTime.Now;
entry.Entity.LastModified = _dateTime.GetUtcNow();
}
}
}
Expand Down
Loading

0 comments on commit 4c06837

Please sign in to comment.