Example #1
1
        IList<ReceiptItem> MergeReceiptItems(IList<BoughtProduct> boughtProducts)
        {
            string[] barcodes = boughtProducts.Select(bp => bp.Barcode).Distinct().ToArray();
            Dictionary<string, Product> boughtProductSet = m_productRepository
                .GetByBarcodes(barcodes)
                .ToDictionary(p => p.Barcode, p => p);
            Dictionary<string,int> boughtDictionary = boughtProducts.GroupBy(bp => bp.Barcode)
                .ToDictionary(g => g.Key, g => g.Sum(bp => bp.Amount));
            var buyTwoGetOne = new BuyTwoGetOne(m_promotionRepository, m_productRepository);
            Dictionary<string, decimal> boughtProductPromoted = buyTwoGetOne.GetPromoted(boughtDictionary);

            return boughtProducts
                .GroupBy(bp => bp.Barcode)
                .Select(g => new ReceiptItem(boughtProductSet[g.Key], g.Sum(bp => bp.Amount),boughtProductPromoted[g.Key]))
                .ToArray();
        }
Example #2
0
        decimal CalculateSinglePromoted(string[] promotionTypes, ReceiptItem receiptItem)
        {
            if (promotionTypes.Length == 0)
            {
                return 0M;
            }

            decimal promoted = receiptItem.Promoted;

            foreach (string type in promotionTypes)
            {
                switch (type)
                {
                    case "BUY_TWO_GET_ONE":
                        ICalculatePromotion calculate = new BuyTwoGetOne();
                        promoted += calculate.CalculatePromoted(receiptItem);
                        break;;
                }
            }
            return promoted;
        }