comments ...
This commit is contained in:
parent
fdf5ee915e
commit
710c04d5f9
6 changed files with 32 additions and 17 deletions
|
|
@ -38,6 +38,8 @@ namespace Yavsc.Models
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Yavsc.Server.Models.Calendar;
|
||||
using Yavsc.Controllers;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
|
||||
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
||||
{
|
||||
|
|
@ -88,7 +90,7 @@ namespace Yavsc.Models
|
|||
|
||||
builder.Entity<Activity>().Property(a=>a.ParentCode).IsRequired(false);
|
||||
//builder.Entity<BlogPost>().HasOne(p => p.Author).WithMany(a => a.Posts);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// this is not a failback procedure.
|
||||
|
|
@ -202,11 +204,11 @@ namespace Yavsc.Models
|
|||
public DbSet<GeneralSettings> GeneralSettings { get; set; }
|
||||
public DbSet<CoWorking> CoWorking { get; set; }
|
||||
|
||||
private void AddTimestamps(string currentUsername)
|
||||
private void AddTimestamps(string userId)
|
||||
{
|
||||
var entities =
|
||||
ChangeTracker.Entries()
|
||||
.Where(x => x.Entity.GetType().GetInterface("IBaseTrackedEntity") != null
|
||||
.Where(x => x.Entity.GetType().GetInterface(nameof(ITrackedEntity)) != null
|
||||
&& (x.State == EntityState.Added || x.State == EntityState.Modified));
|
||||
|
||||
|
||||
|
|
@ -215,19 +217,22 @@ namespace Yavsc.Models
|
|||
if (entity.State == EntityState.Added)
|
||||
{
|
||||
((ITrackedEntity)entity.Entity).DateCreated = DateTime.Now;
|
||||
((ITrackedEntity)entity.Entity).UserCreated = currentUsername;
|
||||
((ITrackedEntity)entity.Entity).UserCreated = userId;
|
||||
}
|
||||
|
||||
((ITrackedEntity)entity.Entity).DateModified = DateTime.Now;
|
||||
((ITrackedEntity)entity.Entity).UserModified = currentUsername;
|
||||
((ITrackedEntity)entity.Entity).UserModified = userId;
|
||||
}
|
||||
}
|
||||
|
||||
public int SaveChanges(string userId)
|
||||
{
|
||||
AddTimestamps(userId);
|
||||
return base.SaveChanges();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<int> SaveChangesAsync(string userId, CancellationToken ctoken = default(CancellationToken))
|
||||
{
|
||||
AddTimestamps(userId);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue