public bool Delete(Orders orderToDelete) { ctx.Orders.Attach(orderToDelete); ctx.Entry(orderToDelete).State = System.Data.Entity.EntityState.Modified; if (orderToDelete.IsActiv == true) { orderToDelete.IsActiv = false; } int count = ctx.SaveChanges(); return(count > 0); }
public bool Delete(Orders orderToDelete) { ctx = new Movies_Rental_DBEntities(); // 1) attach the employee to the context (in the memory) ctx.Orders.Attach(orderToDelete); // 2) mark the employee as "need to be updated" ctx.Entry(orderToDelete).State = System.Data.Entity.EntityState.Modified; if (orderToDelete.IsActiv == true) { orderToDelete.IsActiv = false; } // 3) save the changes in the database int count = ctx.SaveChanges(); return(count > 0); }