private void buttonCheckOut_Click(object sender, EventArgs e)
        {
            var receipt = shoppingService.Checkout(cart);

            printer.PrintReceipt(receipt);
            MessageBox.Show("Receipt output successful.");

            this.Close();
        }
 public void Checkout(BuyRequest request)
 {
     ShoppingService.Checkout(
         request.PromoCode,
         DateTime.Now,
         () => {
         var member = MemberRepository.FindById(ContextualMemberId);
         if (member == null)
         {
             throw new InternalException(ContextualMemberId);
         }
         return(member);
     },
         () => ItemRepository.FindByIds(request.ItemIds) ?? new Item[] { },
         total => {
         LoggingService.Log(LogLevel.Info, $"Member {ContextualMemberId} charged {total}");
         PaymentService.Charge(ContextualMemberId, total);
     });
 }
        public void Member_is_charged_per_discounts(
            IEnumerable <Item> items,
            Member member,
            string promoCode,
            DateTime checkoutTime,
            decimal expectedTotalCharged)
        {
            // Arrange
            var chargeMemberMock = new Mock <Action <decimal> >();

            // Act
            ShoppingService.Checkout(
                promoCode,
                checkoutTime,
                () => member,
                () => items,
                chargeMemberMock.Object);

            // Assert
            chargeMemberMock.Verify(item => item(expectedTotalCharged), Times.Once);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please add the desired items in the cart. When finished press q! for checkout. \n\nTip: Type an Item name and press enter for every individual item.\n\n---------------------- \n");

            while (true)
            {
                string userInput = Console.ReadLine().ToUpper();
                if (userInput == "Q!")
                {
                    break;
                }

                bool addSuccessful = _shoppingService.AddCartItem(userInput);

                if (addSuccessful)
                {
                    Console.WriteLine("SUCCESS: Item successfully added. Please add another one or checkout.");
                    continue;
                }
                else if (!addSuccessful)
                {
                    Console.WriteLine("FAILURE: Please add a valid item.");
                    continue;
                }
            }

            decimal totalPrice = _shoppingService.Checkout();

            if (totalPrice == 0)
            {
                Console.WriteLine($"The basket is empty. No need to checkout. Thank you for shopping with us.");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine($"Checkout SUCCESSFUL, Please pay £{totalPrice}. Thank you for shopping with us.");
                Console.ReadLine();
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            ShoppingService shoppingService = new ShoppingService();

            var allProducts = shoppingService.GetAllProducts();

            allProducts.ForEach(i => Console.WriteLine(i));

            var cart = shoppingService.CreateShoppingCart();

            string input   = "";
            bool   canExit = false;

            //string removeCmd = "";

            do
            {
                Console.WriteLine("please input product id or command...");

                input = Console.ReadLine().ToLower();

                switch (input)
                {
                case "exit":
                case "quit":
                    canExit = true;
                    break;

                case "checkout":
                    var receipt = shoppingService.Checkout(cart.Id);
                    Console.WriteLine(receipt);
                    canExit = true;
                    break;

                case "list":
                    var list = shoppingService.GetShoppingCartItems(cart.Id);
                    list.ForEach(i => Console.WriteLine(i));
                    break;

                default:
                    break;
                }

                /*
                 * if (input.StartsWith(removeCmd))
                 * {
                 *  string id = input.Substring(removeCmd.Length);
                 *  int prodId = ParseProductId(id);
                 *
                 *  if (prodId > 0)
                 *  {
                 *      shoppingService.RemoveProduct(cart.Id, prodId);
                 *  }
                 *  continue;
                 * }
                 */
                int productId = 0;

                if (int.TryParse(input, out productId))
                {
                    var buy = shoppingService.BuyProduct(cart.Id, productId);
                    Console.WriteLine(buy.ToString());
                }
                else
                {
                    Console.WriteLine("please input right product id");
                }
            } while (!canExit);

            cart.ShoppingItems.ForEach(i => Console.WriteLine($"ProductId={i.ProductId}, Count={i.Count}, TotalPrice={i.TotalPrice}"));

            Console.WriteLine("thank you, bye");
            Console.ReadLine();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            ShoppingService shoppingService = new ShoppingService();
            ProductService  productService  = new ProductService();
            ShoppingCart    cart            = new ShoppingCart();
            Printer         printer         = new Printer();

            bool canExit = false;

            do
            {
                Console.WriteLine("--------");
                Console.WriteLine("please type your command:");
                Console.WriteLine("example:");
                Console.WriteLine("get all products");
                Console.WriteLine("add product {id}");
                Console.WriteLine("remove product {id}");
                Console.WriteLine("check shoppingcart");
                Console.WriteLine("checkout");
                Console.WriteLine("q to exit app.");
                Console.WriteLine("--------");

                var command       = Console.ReadLine().ToLowerInvariant();
                var commandSplits = command.Split(' ');

                if (command.StartsWith("get all products"))
                {
                    var products = productService.GetAllProducts();

                    foreach (var item in products)
                    {
                        Console.WriteLine(item);
                    }

                    continue;
                }

                if (command.StartsWith("add product"))
                {
                    var id = int.Parse(commandSplits[2]);

                    shoppingService.AddShoppingItem(cart, id);
                    shoppingService.CheckShoppingCart(cart);

                    continue;
                }

                if (command.StartsWith("remove product"))
                {
                    var id = int.Parse(commandSplits[2]);

                    shoppingService.RemoveShoppingItem(cart, id);
                    shoppingService.CheckShoppingCart(cart);

                    continue;
                }

                if (command.StartsWith("check shoppingcart"))
                {
                    shoppingService.CheckShoppingCart(cart);

                    continue;
                }

                if (command.StartsWith("checkout"))
                {
                    var receipt = shoppingService.Checkout(cart);
                    printer.PrintReceipt(receipt);

                    canExit = true;
                    continue;
                }

                if (command == "q")
                {
                    canExit = true;
                    continue;
                }

                Console.WriteLine("Wrong command, please try again.");
            } while (!canExit);

            Console.WriteLine("Bye.");
            Console.ReadLine();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            ProductService  productService  = new ProductService();
            ShoppingService shoppingService = new ShoppingService();
            ShoppingCart    shoppingCart    = new ShoppingCart();

            string command = "";

            do
            {
                Console.WriteLine("============ Product Admin =============");
                Console.WriteLine("Please type your command:");
                Console.WriteLine("Add to cart id quantity");
                Console.WriteLine("Remove from cart id quantity");
                Console.WriteLine("Check shoppingCart");
                Console.WriteLine("Checkout");
                Console.WriteLine("Find product id");
                Console.WriteLine("List all products");
                Console.WriteLine("quit");
                Console.WriteLine("-----------------------------------------");

                command = Console.ReadLine().ToLowerInvariant();
                var commandSplit = command.Split(' ');

                if (command.StartsWith("add to cart"))
                {
                    try
                    {
                        var id           = int.Parse(commandSplit[3]);
                        var quantity     = int.Parse(commandSplit[4]);
                        var shoppingItem = shoppingService.AddShoppingItem(shoppingCart, id, quantity);
                        Console.WriteLine(shoppingItem);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    continue;
                }

                if (command.StartsWith("remove from cart"))
                {
                    try
                    {
                        var id           = int.Parse(commandSplit[3]);
                        var quantity     = int.Parse(commandSplit[4]);
                        var shoppingItem = shoppingService.RemoveFromCart(shoppingCart, id, quantity);
                        if (shoppingItem != null)
                        {
                            Console.WriteLine(shoppingItem);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    continue;
                }

                if (command.StartsWith("check shoppingcart"))
                {
                    Console.WriteLine(shoppingService.CheckShoppingCart(shoppingCart));
                    continue;
                }

                if (command.StartsWith("checkout"))
                {
                    Receipt receipt = shoppingService.Checkout(shoppingCart);
                    shoppingService.SaveReceipt(receipt);
                    Console.WriteLine(receipt.ToString());
                    continue;
                }

                if (command.StartsWith("find product"))
                {
                    var id      = int.Parse(commandSplit[2]);
                    var product = productService.GetPRoductById(id);
                    if (product == null)
                    {
                        Console.WriteLine($"Product id={id} does not exist");
                    }
                    else
                    {
                        Console.WriteLine("Found this product:");
                        Console.WriteLine(product);
                    }
                    continue;
                }

                if (command.StartsWith("list all product"))
                {
                    Console.WriteLine(productService.ListAllProducts());
                    continue;
                }
            } while (command != "quit");
        }