public async Task <bool> AddRefreshToken(RefreshToken token) { var existingToken = ctx.RefreshTokens.Where(r => r.Subject == token.Subject && r.ClientId == token.ClientId).SingleOrDefault(); if (existingToken != null) { var result = await RemoveRefreshToken(existingToken); } ctx.RefreshTokens.Add(token); return(await ctx.SaveChangesAsync() > 0); }
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 Delete(int id) { using (var ctx = new MyNoteContext()) { var note = ctx.Notes.Find(id); ctx.Notes.Remove(note); //var note = ctx.Notes.First(n => n.Id == id); //ctx.Remove(note); await ctx.SaveChangesAsync(); } }
public async Task Insert(Note note) { using (var ctx = new MyNoteContext()) { note.Created = note.Modified = DateTime.Now; //TODO: return Id //ctx.Notes.Add(note); var zzz = ((DbSet <Note>)ctx.Set <Note>()) .Add(note); 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(); } }
public async Task Update(Note note) { using (var ctx = new MyNoteContext()) { var dbNote = ctx.Notes.First(u => u.Id == note.Id); note.Created = dbNote.Created; note.Modified = DateTime.Now; ctx.Entry(dbNote).CurrentValues.SetValues(note); await ctx.SaveChangesAsync(); //var dbNote = ctx.Notes.Find(note.Id); //dbNote.Lead = note.Lead; //dbNote.Modified = DateTime.Now; //dbNote.ShareLink = note.ShareLink; //dbNote.Title = note.Title; //return ctx.SaveChangesAsync(); } }