public async Task <IActionResult> PutNote([FromRoute] int id, [FromBody] Note note) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != note.ID) { return(BadRequest()); } _context.Entry(note).Property("Text").CurrentValue = note.Text; _context.Entry(note).Property("Text").IsModified = true; try { _context.SaveChanges(); _context.Entry(note).Reload(); } catch (DbUpdateConcurrencyException) { if (!NoteExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private Task DeleteNote(Note note) { using (var context = new NotesContext()) { var noteDb = context.Notes.FirstOrDefault(x => x.Id == note.Id); noteDb.DeletedDate = DateTime.Now; context.Update(noteDb); context.SaveChanges(); } return(Task.CompletedTask); }
private Task Save() { using (var context = new NotesContext()) { foreach (var note in notes) { var noteDb = context.Notes.FirstOrDefault(x => x.Id == note.Id && x.DeletedDate == null); if (noteDb is null) { context.Add(note); } else { noteDb.Text = note.Text; noteDb.IsCompleted = note.IsCompleted; context.Update(noteDb); } } context.SaveChanges(); } return(Task.CompletedTask); }