Beispiel #1
0
        public ISellResponse Sell(ISellRequest sellRequest)
        {
            var sellResonse = new SellResponse();

            foreach (var product in sellRequest.Products)
            {
                //get discount based on usertype and product
                var  discounts   = _dataAccess.GetDiscount(product, sellRequest.UserType);
                var  soldProduct = new SoldProduct();
                bool isSold      = false;
                if (discounts == null)
                {
                    var sellingPrice = product.Price;
                    isSold = Sell(product, sellingPrice);
                }
                else
                {
                    //if there are multiple discounts choose the max
                    var discount     = ChooseMaxDiscount(product.Price, discounts);
                    var sellingPrice = product.Price - discount;
                    isSold = Sell(product, sellingPrice);
                }

                sellResonse.SoldProducts.Add(soldProduct);
            }
            return(sellResonse);
        }
Beispiel #2
0
        private ISellReportResponse CreateSellReport(IEnumerable <ISellHistory> historyList)
        {
            var response     = new SellReportResponse();
            var soldProducts = new List <SoldProduct>();

            foreach (var historyEntry in historyList)
            {
                var soldProduct = new SoldProduct();
                soldProduct.Quantity     = historyEntry.Quantity;
                soldProduct.Id           = historyEntry.ProductId;
                soldProduct.Name         = _dataAccess.GetProductById(historyEntry.ProductId).Name;
                soldProduct.SellingPrice = historyEntry.SellingPrice;

                soldProducts.Add(soldProduct);
            }

            response.Products = soldProducts;
            return(response);
        }