Example #1
0
        public CheckoutBasket CheckoutBasket()
        {
            var distinctBooks = _bookBasket.BooksInBasket.Select(x => x.Quantity).Where(x => x > 0).ToArray();

            var checkoutBasket = new CheckoutBasket()
            {
                BooksPurchased = _bookBasket, UndiscountedBooks = distinctBooks, DiscountedPriceTotal = 0
            };

            var potentialCheckoutBaskets = GeneratePossibleCheckoutValues(new List <CheckoutBasket>()
            {
                checkoutBasket
            });

            var lowestPricedBasket = potentialCheckoutBaskets.OrderBy(x => x.DiscountedPriceTotal).First();

            return(lowestPricedBasket);
        }
Example #2
0
        private List <CheckoutBasket> IteratePossibleDiscounts(List <CheckoutBasket> updatedBaskets, CheckoutBasket basket, int[] booksToProcess)
        {
            for (int booksInDiscount = 2; booksInDiscount <= booksToProcess.Count(); booksInDiscount++)
            {
                var discount = _discounts.Where(x => x.NumberOfBooks == booksInDiscount).FirstOrDefault();

                var discountsApplied = new List <Discount>(basket.DiscountsApplied);
                discountsApplied.Add(discount);

                var updatedBasket = new CheckoutBasket()
                {
                    BooksPurchased       = basket.BooksPurchased,
                    UndiscountedBooks    = UpdateUndiscountedBooksRecord(booksToProcess, booksInDiscount),
                    DiscountedPriceTotal = basket.DiscountedPriceTotal + discount.TotalCost,
                    DiscountsApplied     = discountsApplied
                };

                updatedBaskets.Add(updatedBasket);
            }

            return(updatedBaskets);
        }