Ejemplo n.º 1
0
        public Order(Basket basket, Address address, int orderID)
        {
            ID          = orderID;
            this.basket = basket;

            var basketItems = basket.GetCopyOfListOfItemsInBasket();

            Console.WriteLine("\nPagamento realizado!");

            BasketManager.PrintAllBasketItems(basketItems);

            foreach (var product in basketItems.Keys)
            {
                // sum every product quantity by its price to get total order price
                TotalPrice += product.Price * basketItems[product];
            }

            Console.WriteLine("\nValor total do pedido: {0}", TotalPrice);

            Console.WriteLine("\nPedido efetuado com sucesso!\nOs produtos serão separados e entregues em ate 20 minutos para o cliente {0} no endereço:\n{1} - {2} - {3}",
                              address.CustomerName, address.City, address.Street, address.Number);
        }
Ejemplo n.º 2
0
        public void AddOrUpdateItemToBasket(Product product, int quantityOfProductToBeAddedOrUpdatedInBasket)
        {
            var quantityOfProductsInStock = Stock.GetStockQuantityOfProduct(product);

            // add item to basket if this basket does not contain this product, else only update it's quantit
            if (!basketItem.ContainsKey(product))
            {
                // check if quantity of product that customer asked for is available in stock
                if (quantityOfProductsInStock >= quantityOfProductToBeAddedOrUpdatedInBasket)
                {
                    basketItem.Add(product, quantityOfProductToBeAddedOrUpdatedInBasket);
                }
                else
                {
                    basketItem.Add(product, quantityOfProductsInStock);
                    Console.WriteLine
                        ("\nA quantidade do produto {0} excede a quantidade disponivel ({1} unidades) no estoque.\nO pedido foi efetuado considerando apenas a quantidade disponivel no estoque", product.Name, quantityOfProductsInStock);
                }
            }
            else
            {
                // check if quantity of product that customer asked for is available in stock
                if (quantityOfProductsInStock >= quantityOfProductToBeAddedOrUpdatedInBasket)
                {
                    basketItem[product] = quantityOfProductToBeAddedOrUpdatedInBasket;
                }
                else
                {
                    basketItem[product] = quantityOfProductsInStock;
                    Console.WriteLine
                        ("\nA quantidade do produto {0} excede a quantidade disponivel ({1} unidades) no estoque.\nO pedido foi efetuado considerando apenas a quantidade disponivel no estoque", product.Name, quantityOfProductsInStock);
                }
            }
            Console.WriteLine("\nItem adicionado ao carrinho:\nProduto: {0}    |     Quantidade: {1}    |     Valor unitario: {2}", product.Name, basketItem[product], product.Price);

            var basketItems = this.GetCopyOfListOfItemsInBasket();

            BasketManager.PrintAllBasketItems(basketItems);
        }
Ejemplo n.º 3
0
        public static void AskCustomerToCreateOrderOrBuyMore(Basket basket)
        {
            Console.WriteLine("\nDigite 1 para finalizar a compra, 2 para visualizar o cardapio novamente para adicionar novos itens ao carrinho ou 3 para cancelar a compra e visualizar o cardapio");
            var customerOptionToCreateOrderOrBuyMoreItems = int.Parse(Console.ReadLine());

            Console.Clear();
            switch (customerOptionToCreateOrderOrBuyMoreItems)
            {
            case 1:
                // create order and finish application
                var address    = AskForCustomerAddress();
                var creditCard = AskForCustomerCreditCard();
                OrderRegister.CreateOrder(new Order(basket, address, orderID++));
                break;

            case 2:
                // send customer back to fill basket with an existing basket
                PrintListOfProductsAvailableToSell();
                var basketItems = basket.GetCopyOfListOfItemsInBasket();
                BasketManager.PrintAllBasketItems(basketItems);
                var basketUpdated = AskForWhichProductsCustomerWantsToBuy(basket);
                AskCustomerToCreateOrderOrBuyMore(basketUpdated);
                break;

            case 3:
                // send customer back to fill basket with an empty basket
                PrintListOfProductsAvailableToSell();
                var newBasket = AskForWhichProductsCustomerWantsToBuy();
                AskCustomerToCreateOrderOrBuyMore(newBasket);
                break;

            default:
                // AskCustomerToCreateOrderOrBuyMore again
                Console.WriteLine("\nOpcao invalida.");
                AskCustomerToCreateOrderOrBuyMore(basket);
                break;
            }
        }