public async Task <IActionResult> PutNotes([FromRoute] int id, [FromBody] Notes notes) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != notes.ID) { return(BadRequest()); } //var temp2 = GetNotes().SingleOrDefault(x => x.ID == id); await _context.Notes.Include(x => x.checklist).Include(x => x.label).ForEachAsync(x => { if (x.ID == id) { // x = notes; //_context.UpdateRange(); x.Title = notes.Title; x.Text = notes.Text; x.PinStat = notes.PinStat; _context.Label.RemoveRange(x.label); _context.Label.AddRange(notes.label); _context.Check.RemoveRange(x.checklist); _context.Check.AddRange(notes.checklist); } }); //_context.Entry(notes).State = EntityState.Modified; // _context.Notes.Update(notes); await _context.SaveChangesAsync(); return(Ok(_context.Notes.Include(y => y.label).Include(y => y.checklist).First(x => x.ID == notes.ID))); }
public async Task <IActionResult> PutToDo([FromRoute] int id, [FromBody] Notes note) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != note.ID) { return(BadRequest()); } //await _context.Note.Include(x => x.ListofLabels).Include(x => x.ListofChecks).SingleOrDefaultAsync(n => n.NoteID == id); _context.Notes.Update(note); //_context.Entry(note).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException e) { if (!NotesExists(id)) { return(NotFound()); } else { throw; } } return(Ok(note)); }