/// <summary> /// Adds to shopping cart. /// </summary> /// <param name="userInput">The user input.</param> ////NOTE: TOO MANY CONDITIONS BUT THOUGHT TO VALIDATE SOME USER INPUTS. public ShoppingCart AddToShoppingCart(string userInput) { var shoppingCart = new ShoppingCart(); if (!Validate(userInput)) return shoppingCart; var product = productTasks.GetProductById(Convert.ToInt32(userInput)); if (product != null) { return ProcessShoppingCart(product, shoppingCart); } defaultConsole.WriteLine(Messages.ProductDoesnotExist); return shoppingCart; }
/// <summary> /// Applies the voucher on basket. /// </summary> /// <param name="shoppingCart">The shopping cart.</param> /// <param name="voucher">The voucher.</param> public void ApplyVoucherOnBasket(ShoppingCart shoppingCart, Voucher voucher) { shoppingCart.Voucher = voucher; defaultConsole.WriteLine(Messages.TotalCostAfterDiscount, shoppingCart.TotalCostAfterDiscount); defaultConsole.WriteLine(Messages.VoucherCodeStatusMessage, shoppingCart.Message); }
private ExitCode Run() { defaultConsole.WriteLine(Messages.ProductsTitle); DisplayAllProducts(); var shoppingCart = new ShoppingCart(); while(true) { var userInput = Console.ReadLine(); if (!Equals(userInput, CheckoutUserInput)) { shoppingCart = AddToShoppingCart(userInput); } else if(Equals(userInput, CheckoutUserInput)) { ProcessCheckout(shoppingCart); } else { break; } } return ExitCode.Success; }
private ShoppingCart ProcessShoppingCart(GenericProduct product, ShoppingCart shoppingCart) { defaultConsole.WriteLine(Messages.EnterQuantity); while (true) { var quantityInput = Console.ReadLine(); if (Validate(quantityInput)) { var shoppingCartItem = MapUserInputToDomain(product, quantityInput); shoppingCart = this.shoppingCartTasks.AddToShoppingCart(shoppingCartItem); DisplayCartInformation(shoppingCart); break; } } return shoppingCart; }
/// <summary> /// Processes the checkout. /// </summary> private void ProcessCheckout(ShoppingCart shoppingCart) { while (true) { defaultConsole.WriteLine(Messages.EnterVoucherCode); var voucherCode = Console.ReadLine(); var voucher = CheckIfExists(voucherCode); if(voucher != null) { ApplyVoucherOnBasket(shoppingCart, voucher); } else { defaultConsole.WriteLine(Messages.VoucherNotVallid); break; } } }
/// <summary> /// Displays the cart information. /// </summary> /// <param name="shoppingCart">The shopping cart.</param> private void DisplayCartInformation(ShoppingCart shoppingCart) { defaultConsole.WriteLine(Messages.YourBasketContains); foreach (var item in shoppingCart.Items) { defaultConsole.WriteLine(Messages.ShoppingCartItems, item.Id, item.Product.Name, item.Quantity, item.Product.Cost, item.TotalCost); } defaultConsole.WriteLine(Messages.YourTotalBasketCost,shoppingCart.TotalCost); defaultConsole.WriteLine(Messages.TotalBasketCostWithoutGiftVouchers, shoppingCart.TotalCostExcludingGiftVouchers); defaultConsole.WriteLine(Messages.SelectAnotherProduct); }
/// <summary> /// Initializes the <see cref="ShoppingCartFactory"/> class. /// </summary> static ShoppingCartFactory() { ShoppingCart = new ShoppingCart(); }
/// <summary> /// Removes the specified entity. /// </summary> /// <param name="entity">The entity.</param> public void Remove(ShoppingCart entity) { throw new NotImplementedException(); }