private async Task AuditNoteActions(Note note, AuditAction action) { using (var ctx = new MyNoteContext()) { var auditNote = new AuditEnrty() { Action = Enum.GetName(typeof(AuditAction), action), NoteId = note.Id, Actor = note.Owner, Time = DateTime.Now }; switch (action) { case AuditAction.CreateNote: case AuditAction.UpdateNote: auditNote.Details = $"Title:{note.Title}, Content:{note.Content}"; break; case AuditAction.ShareNote: auditNote.Details = $"ShareLink:{note.ShareLink}"; break; } ctx.AuditEntries.Add(auditNote); await ctx.SaveChangesAsync(); } }
public async Task RegisterUser(UserModel user, IdentityResult identityResult) { using (var ctx = new MyNoteContext()) { var auditNote = new AuditEnrty() { Action = Enum.GetName(typeof(AuditAction), AuditAction.RegisterUser), Actor = user.UserName, Time = DateTime.Now, Details = identityResult.Succeeded ? "Success." : string.Join("; ", identityResult.Errors) }; ctx.AuditEntries.Add(auditNote); await ctx.SaveChangesAsync(); } }