public void ProductDispocal(IEnumerable <DisposalProduct> disposalProducts, int locationID, int reasonID) { ProductDisposal productDisposal = new ProductDisposal(); productDisposal.Date = DateTime.Now; productDisposal.LocationId = locationID; productDisposal.ReasonId = reasonID; productDisposal.Products = new List <DisposalProduct>(); foreach (var disposalProduct in disposalProducts) { var operation = new Operation(); var product = context.ProductStorage.Where(x => x.ProductId == disposalProduct.ProductId && x.LocationID == locationID).FirstOrDefault(); if (product != null && product.Value >= disposalProduct.Amount) { operation.Date = DateTime.Now; operation.Name = "Списание"; operation.Value = disposalProduct.Amount * -1; operation.ProductId = disposalProduct.ProductId; product.Value -= disposalProduct.Amount; disposalProduct.Price = product.Price; context.Operation.Add(operation); context.Entry(product).State = EntityState.Modified; productDisposal.Products.Add(disposalProduct); } } ProductDRep.Add(productDisposal); Save(); }
public void Update(ProductDisposal entity) { context.Entry(entity).State = EntityState.Modified; }
public void Remove(ProductDisposal entity) { context.ProductDisposal.Remove(entity); }
public void Add(ProductDisposal entity) { context.ProductDisposal.Add(entity); }