public void UpdatePrice(Product item, decimal price) { using (var context = new DbStorehouse()) { var priceAdd = new PriceStore() { ProductId = item.ProductId, DateEdited = DateTime.Now, Price = price }; var priceStore = context.PriceStores.Add(priceAdd); context.SaveChanges(); item.PriceId = priceStore.PriceId; context.Entry(item).State = EntityState.Modified; context.SaveChanges(); } }
public void Update(Product item) { using (var context = new DbStorehouse()) { context.Entry(item).State = EntityState.Modified; context.SaveChanges(); } }
public Product Create(Product item) { using (var context = new DbStorehouse()) { context.Products.Add(item); context.SaveChanges(); return(item); } }
public void Remove(int id) { using (var context = new DbStorehouse()) { var product = context.Products.Find(id); product.IsDelete = true; context.Entry(product).State = EntityState.Modified; context.SaveChanges(); } }
public void UpdateCount(Product item, int count, bool balance) { using (var context = new DbStorehouse()) { var countAdd = new CountStore { ProductId = item.ProductId, PriceId = item.PriceId.GetValueOrDefault(), DateEdited = DateTime.Now, CountUp = balance ? count : 0, CountDown = balance ? 0 : count } ; //item.CountStores = countAdd; context.CountStores.Add(countAdd); context.Entry(item).State = EntityState.Modified; context.SaveChanges(); } }