public async Task CreateUser() { if (!_dbContext.Users.Any(u => u.IdentityId == _currentUserService.GetCurrentUserIdentity())) { var user = new User { Id = Guid.NewGuid().ToString(), IdentityId = _currentUserService.GetCurrentUserIdentity() }; await _dbContext.Users.AddAsync(user); await _dbContext.SaveChangesAsync(); } }
public override Task <int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken()) { foreach (var entry in ChangeTracker.Entries <AuditableEntity>()) { switch (entry.State) { case EntityState.Added: entry.Entity.Created = _dateProvider.Now; entry.Entity.CreatedBy = _currentUserService.GetCurrentUserIdentity(); break; case EntityState.Modified: entry.Entity.LastModified = _dateProvider.Now; entry.Entity.LastModifiedBy = _currentUserService.GetCurrentUserIdentity(); break; } } return(base.SaveChangesAsync(cancellationToken)); }
public async Task <IActionResult> GetUserIdentity() { return(Ok(_currentUserService.GetCurrentUserIdentity())); }