public void DeleteProduct(int pId) { using (var ctx = new BirovAmContext()) { List <ProductsSize> ps = ctx.ProductsSizes.Where(x => x.ProductID == pId).ToList(); foreach (ProductsSize pr in ps) { ctx.Entry(pr).State = EntityState.Deleted; } Product p = ctx.Products.Where(x => x.ProductID == pId).FirstOrDefault(); ctx.Entry(p).State = EntityState.Deleted; ctx.SaveChanges(); } }
public void AddProductSizes(List <ProductsSize> ps) { using (var ctx = new BirovAmContext()) { foreach (ProductsSize s in ps) { ProductsSize prs = ctx.ProductsSizes.Where(i => i.ProductID == s.ProductID && i.SizeID == s.SizeID).FirstOrDefault(); if (prs == null) { if (s.Included) { ctx.ProductsSizes.Add(s); } } else { if (s.Included) { if (prs.Stock != s.Stock) { prs.Stock = s.Stock; } } else { ctx.Entry(prs).State = EntityState.Deleted; } } ctx.SaveChanges(); } } }
public void EditCustomer(Customer c) { using (var ctx = new BirovAmContext()) { ctx.Entry(c).State = EntityState.Modified; ctx.SaveChanges(); } }
public void EditProduct(Product p) { using (var ctx = new BirovAmContext()) { ctx.Entry(p).State = EntityState.Modified; ctx.SaveChanges(); } }
public void DeleteSize(int sId) { using (var ctx = new BirovAmContext()) { Size s = ctx.Sizes.Where(si => si.SizeID == sId).FirstOrDefault(); ctx.Entry(s).State = EntityState.Deleted; ctx.SaveChanges(); } }
public void DeleteCategory(int cId) { using (var ctx = new BirovAmContext()) { Category c = ctx.Categories.Where(x => x.CategoryID == cId).FirstOrDefault(); ctx.Entry(c).State = EntityState.Deleted; ctx.SaveChanges(); } }
public void DeleteOrderDetail(int odId, int oId) { using (var ctx = new BirovAmContext()) { OrderDetail od = ctx.OrderDetails.Where(d => d.OrderDetailID == odId).FirstOrDefault(); ProductsSize ps = ctx.ProductsSizes.Where(p => p.ProductID == od.ProductID && p.SizeID == od.SizeID).FirstOrDefault(); if (ps != null) { ps.Stock += od.Quantity.Value; } ctx.Entry(od).State = EntityState.Deleted; ctx.SaveChanges(); Order order = ctx.Orders.Where(o => o.OrderID == oId).FirstOrDefault(); order.TotalCost = ctx.OrderDetails.Where(x => x.OrderID == oId && x.DeleteFlag != true).Sum(x => x.Price); order.TotalQuantity = ctx.OrderDetails.Where(x => x.OrderID == oId && x.DeleteFlag != true).Sum(x => x.Quantity); ctx.SaveChanges(); } }