public void Delete(Person personToDelete) { if (_dbContext.Entry(personToDelete).State == Microsoft.EntityFrameworkCore.EntityState.Detached) { _dbContext.Attach(personToDelete); } _dbContext.Remove(personToDelete); _dbContext.SaveChanges(); }
public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,Adress,PhoneNumbers")] Contact contact) { if (ModelState.IsValid) { foreach (PhoneNumber PhNum in contact.PhoneNumbers) { db.Entry(PhNum).State = EntityState.Modified; } db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contact)); }
public async Task <IHttpActionResult> PutContact(int id, Contact contact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } contact.ContactId = id; _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 <IActionResult> PutContactListItem([FromRoute] long id, [FromBody] ContactListItem contactListItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != contactListItem.Id) { return(BadRequest()); } _context.Entry(contactListItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactListItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public HttpStatusCodeResult PutContact(int id, Contact contact) { if (!ModelState.IsValid) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Bad Request")); } if (id != contact.ContactId) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Bad Request")); } db.Entry(contact).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Not Found")); } else { throw; } } return(new HttpStatusCodeResult(HttpStatusCode.NoContent, "No Content")); }
public ActionResult Edit(Contact contact) { if (ModelState.IsValid) { db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contact)); }
public async Task <IActionResult> PutContactListItem([FromRoute] long id, [FromBody] ContactListItem contactListItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Entry(contactListItem).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(contactListItem)); }
public void Update(Phone obj) { _context.Entry(obj).State = EntityState.Modified; _context.SaveChanges(); }
public ActionResult ContactUpdate(ContactList diary) { db.Entry(diary).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "ContactList")); }
public T Update(T obj) { _context.Entry(obj).State = EntityState.Modified; return(obj); }