Пример #1
0
        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();
        }
Пример #2
0
 public void Update(ProductDisposal entity)
 {
     context.Entry(entity).State = EntityState.Modified;
 }
Пример #3
0
 public void Remove(ProductDisposal entity)
 {
     context.ProductDisposal.Remove(entity);
 }
Пример #4
0
 public void Add(ProductDisposal entity)
 {
     context.ProductDisposal.Add(entity);
 }