Ejemplo n.º 1
0
 public void AddShipment(Product product, decimal quantity)
 {
     var report = this.GetTodaysReport();
     var shipment = report.Shipments.FirstOrDefault(x => x.Product == product);
     if (shipment != null)
     {
         shipment.Quantity += quantity;
     }
     else
     {
         shipment = new Shipment();
         shipment.Product = product;
         shipment.Quantity = quantity;
         report.Shipments.Add(shipment);
     }
 }
Ejemplo n.º 2
0
        private void MapProperties(Product product, string name, decimal? buyingPrice, decimal? sellingPrice,
                                   MeasureType? measure, decimal? quantity, ICollection<Barcode> barcodes, ICollection<ExpirationDate> expirationDates)
        {
            product.Name = ProductNameFixer.Fix(name);
            product.BuyingPrice = buyingPrice ?? product.BuyingPrice;
            product.SellingPrice = sellingPrice ?? product.SellingPrice;
            product.Measure = measure ?? product.Measure;
            product.Quantity += quantity ?? 0;

            foreach (var barcode in product.Barcodes.Where(barcode => barcodes.All(x => x.Value != barcode.Value)).ToList())
            {
                this.barcodesRepository.Delete(barcode);
            }
            
            foreach (var barcode in barcodes.Where(barcode => !this.barcodesRepository.All().Any(x => x.Value == barcode.Value)))
            {
                product.Barcodes.Add(barcode);
            }

            foreach (var expirationDate in expirationDates.Where(expirationDate => product.ExpirationDates.All(x => x.Date != expirationDate.Date || x.Batch != expirationDate.Batch)))
            {
                product.ExpirationDates.Add(expirationDate);
            }
        }
Ejemplo n.º 3
0
        private decimal CalculateStockPrice(Product product, decimal sellingPrice, decimal quantity)
        {
            decimal stockPrice = 0;

            var sellingPriceDifference = sellingPrice - product.SellingPrice;
            stockPrice += sellingPriceDifference * product.Quantity;
            stockPrice += sellingPrice * quantity;

            return stockPrice;
        }
Ejemplo n.º 4
0
        public void AddOrUpdate(string name, string oldName, decimal? buyingPrice, decimal? sellingPrice,
            MeasureType? measure, decimal? quantity, ICollection<Barcode> barcodes, ICollection<ExpirationDate> expirationDates)
        {
            if (oldName != name && this.productsRepository.All().Where(x => !x.IsDeleted).Any(x => x.Name == name))
            {
                throw new ArgumentException($"A product with name {name} already exists");
            }

            this.missingProductsService.RemoveMissingProducts(barcodes.Select(x => x.Value));

            var product = this.productsRepository.All().FirstOrDefault(x => x.Name == oldName);
            if (product == null)
            {
                product = new Product();
                this.productsRepository.Add(product);
            }

            var stockPrice = this.CalculateStockPrice(product, sellingPrice ?? product.SellingPrice, quantity ?? 0);

            this.MapProperties(product, name, buyingPrice, sellingPrice, measure, quantity, barcodes, expirationDates);

            if (quantity.GetValueOrDefault() != 0)
            {
                this.reportsService.AddShipment(product, quantity.GetValueOrDefault());
            }
            this.reportsService.AddStockPrice(stockPrice);
            this.productsRepository.SaveChanges();
        }