예제 #1
0
        public void Waste(string sellerId, IEnumerable<IdQuantityPair> products)
        {
            var waste = new Waste();

            foreach (var product in products)
            {
                var wastedProduct = this.productsRepository.GetById(product.Id);

                if (wastedProduct == null)
                {
                    throw new ArgumentException($"Product with Id {product.Id} does not exist.", "Id");
                }

                var productWithQuantity = new ProductWithQuantity
                                          {
                                              Product = wastedProduct,
                                              Quantity = product.Quantity
                                          };

                waste.AddProduct(productWithQuantity);

                wastedProduct.Quantity -= product.Quantity;
            }
            
            var seller = this.sellersRepository.GetById(sellerId);
            var report = this.reportsService.GetTodaysReport();

            waste.Seller = seller;
            waste.Report = report;

            this.wasteRepository.Add(waste);
            this.wasteRepository.SaveChanges();
        }
예제 #2
0
 public void AddProduct(ProductWithQuantity productWithQuantity)
 {
     this.Products.Add(productWithQuantity);
     this.Total += productWithQuantity.Product.SellingPrice * productWithQuantity.Quantity;
 }