/// <summary> /// Generic Delete method for the entities /// </summary> /// <param name="entityToDelete"></param> public virtual void Delete(TEntity entityToDelete) { if (Context.Entry(entityToDelete).State == EntityState.Detached) { DbSet.Attach(entityToDelete); } DbSet.Remove(entityToDelete); }
public IHttpActionResult PutContact(int id, Contact contact) { if (id != contact.Id) { return(BadRequest()); } db.Entry(contact).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit(Contact contact) { if (ModelState.IsValid) { db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contact)); }
public HttpResponseMessage UpdateContact(tblContact a_contact) { int result = 0; try { dbContext.tblContacts.Attach(a_contact); dbContext.Entry(a_contact).State = EntityState.Modified; dbContext.SaveChanges(); result = 1; } catch (Exception e) { result = 0; } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public void UpdateContact(Contact contact) { db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); }