Ejemplo n.º 1
0
        private void AddQuantityToCheckoutProductModel(ProductModel selectedProduct, float quantityInput)
        {
            CheckoutProductModel addedProduct = Checkout.Products.FirstOrDefault(p => p.Id == selectedProduct.Id);

            if (addedProduct != null)
            {
                addedProduct.Quantity++;
            }
            else
            {
                CheckoutProductModel checkoutProduct = new CheckoutProductModel
                {
                    Id         = selectedProduct.Id,
                    Code       = selectedProduct.Code,
                    Name       = selectedProduct.Name,
                    Quantity   = quantityInput,
                    Price      = selectedProduct.Price,
                    Categories = selectedProduct.Categories,
                    Promotions = selectedProduct.Promotions
                };
                Checkout.Products.Add(checkoutProduct);
            }
        }
Ejemplo n.º 2
0
        static void Checkout()
        {
            string        productCodeInput = "";
            float         quantityInput    = -1;
            bool          isFloat          = false;
            bool          isExist          = false;
            bool          isMembership     = false;
            double        discountPercent  = 10;
            string        membershipInput;
            CheckoutModel checkout = new CheckoutModel();
            List <CheckoutProductModel> products         = new List <CheckoutProductModel>();
            IProductService             productService   = null;
            IPromotionService           promotionService = null;

            try
            {
                productService   = new ProductService();
                promotionService = new PromotionService();
                Console.Clear();
                Console.WriteLine("-- Checkout --");
                while (isExist == false)
                {
                    ProductModel selectedProduct = null;

                    do
                    {
                        Console.Write("Product Code: ");
                        productCodeInput = Console.ReadLine();
                        isExist          = productCodeInput.ToUpper().Equals("E0");
                        if (isExist == false)
                        {
                            selectedProduct = productService.GetProductInfoByCode(productCodeInput);
                        }
                    }while (isExist == false && selectedProduct == null);

                    if (isExist == false)
                    {
                        do
                        {
                            Console.Write("Quantity: ");
                            isFloat = float.TryParse(Console.ReadLine(), out quantityInput);
                        }while (isFloat == false && quantityInput < 0);

                        CheckoutProductModel addedProduct = products.FirstOrDefault(p => p.Id == selectedProduct.Id);
                        if (addedProduct != null)
                        {
                            addedProduct.Quantity++;
                        }
                        else
                        {
                            CheckoutProductModel checkoutProduct = new CheckoutProductModel
                            {
                                Id         = selectedProduct.Id,
                                Code       = selectedProduct.Code,
                                Name       = selectedProduct.Name,
                                Quantity   = quantityInput,
                                Price      = selectedProduct.Price,
                                Categories = selectedProduct.Categories,
                                Promotions = selectedProduct.Promotions
                            };
                            products.Add(checkoutProduct);
                        }
                    }
                }
                do
                {
                    Console.Write("Membership (Y/N)");
                    membershipInput = Console.ReadLine();
                } while (membershipInput.ToUpper().Equals("Y") == false &&
                         membershipInput.ToUpper().Equals("N") == false);

                isMembership = membershipInput.ToUpper().Equals("Y");
                if (isMembership)
                {
                    var promotion = promotionService.GetPromotionForMembership();
                    if (promotion != null)
                    {
                        checkout.IsMembership       = isMembership;
                        checkout.MembershipDiscount = promotion.Saleoff ?? 0;
                    }
                }
                checkout.Products = products;
                productService.ShowCheckoutResult(checkout);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                productService   = null;
                promotionService = null;
            }
        }