Пример #1
0
        public Receipt GetPromotion(Receipt receipt)
        {
            var receiptItems = receipt.ReceiptItems;
            Promotion[] promotions =
                m_promotionRepository.GetPromotionByBarcodes(
                    receiptItems.Select(r => r.Product.Barcode).ToArray());

            Receipt finalReceipt = new Receipt(receiptItems.Select(
                r =>
                    new ReceiptItem(r.Product,
                        r.Amount,
                        CalculateSinglePromoted(
                            promotions.Where(p => p.BarCode == r.Product.Barcode).Select(p => p.Type).ToArray(),
                            r))).ToArray());

            decimal additionPromoted = CalculateTotalPromoted(finalReceipt, promotions);
            finalReceipt.Promoted += additionPromoted;
            finalReceipt.Total -= additionPromoted;

            return finalReceipt;
        }
Пример #2
0
        decimal CalculateTotalPromoted(Receipt receipt, Promotion[] promotions)
        {
            string[] barcodes =
                promotions.Where(p => p.Type == "BUY_ONE_HUNDRED_CUT_FIFTY")
                    .Select(p => p.BarCode)
                    .ToArray();

            decimal totalAfterPromoted = receipt.ReceiptItems.Where(r => barcodes.Contains(r.Product.Barcode))
                .Select(r => (r.Total - r.Promoted)).Sum();

            return (int)(totalAfterPromoted/100)*50;
        }