public async Task <IHttpActionResult> PutContact(int id, Contact contact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != contact.ContactId) { return(BadRequest()); } db.Entry(contact).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task SaveToDB(Note note) { using (this.context = new NotebookContext()) { context.Notes.Add(note); await context.SaveChangesAsync(); } }
public async Task SaveEditedToDB(Note note) { using (this.context = new NotebookContext()) { var editedNote = await context.Notes.FindAsync(note.Id); if (editedNote != null) { editedNote.Name = note.Name; editedNote.File = note.File; context.Entry(editedNote).State = EntityState.Modified; await context.SaveChangesAsync(); } } }