public void SaveProduct(Product product) { if (product.ProductID == 0) { context.Products.Add(product); } else { if (product.CategoryID != product.Category.CategoryID) { product.Category.CategoryID = product.CategoryID; } context.Entry(product).State = System.Data.EntityState.Modified; } context.SaveChanges(); }
public void SaveProduct(Entities.Product product) { if (product.ProductID == 0) { context.Products.Add(product); } else { Product prodToUpdate = context.Products .Where(p => p.ProductID == product.ProductID).FirstOrDefault(); if (prodToUpdate != null) { context.Entry(prodToUpdate).CurrentValues.SetValues(product); } } context.SaveChanges(); }
public bool SaveProduct(Product product) { try { if (product.ProductID <= 0) { context.Products.Add(product); } else { var forRefresh = context.Products.Find(product.ProductID); if (forRefresh != null) { context.Entry(forRefresh).CurrentValues.SetValues(product); } } context.SaveChanges(); return(true); } catch { return(false); } }
public bool Update(TEntity entity) { Context.Entry(entity).State = EntityState.Modified; return(Context.SaveChanges() > 0); }
public void Edit(Customer cust) { context.Entry(cust).State = EntityState.Modified; context.SaveChanges(); }