public async Task <ActionResult <Models.DTO.NoteDTO> > Post(Models.DTO.NoteDTO note) { Models.Note newNote = null; try { newNote = new Models.Note(note, _dbContext); } catch (Exception ex) { return(BadRequest(ex.Message)); } // Update timestamps newNote.Created = DateTime.Now; newNote.Edited = newNote.Created; _dbContext.Notes.Add(newNote); await _dbContext.SaveChangesAsync(); return(CreatedAtAction( nameof(Get), new { id = newNote.NoteId }, new Models.DTO.NoteDTO(newNote) )); }
public async Task <ActionResult> Put(int id, Models.DTO.NoteDTO note) { if (id != note.Id) { return(BadRequest($"Query param id {id} must match body data id {note.Id}")); } Models.Note dbNote = _dbContext.Notes .Include(n => n.NoteLabels) .AsTracking() .FirstOrDefault(n => n.NoteId == id); if (dbNote == null) { return(NotFound()); } try { dbNote.SetFrom(note, _dbContext); } catch (Exception ex) { return(BadRequest(ex.Message)); } await _dbContext.SaveChangesAsync(); return(NoContent()); }