예제 #1
0
        public static void Main(string[] args)
        {
            ShoppingServices ss = new ShoppingServices();

            var allProducts = ss.GetAllProducts();

            var shoppingCart = ss.CreateShoppingCart();

            do
            {
                allProducts.ForEach(p => { Console.WriteLine(p.ToString()); });

                ss.AddToCart(2, 4);
                ss.ListingShoppingCart();

                ss.AddToWishList(4);
                ss.ListingWishList();

                break;
            } while (true);

            Console.ReadLine();
        }
 public ShoppingController()
 {
     shoppingServices = new ShoppingServices();
     userServices     = new UserServices();
 }
예제 #3
0
        public static void RunShoppingScreen(User user)
        {
            ILogger Trace         = new GenericLoggerAdapter();
            int     userSelection = 0;
            bool    wantsToExit   = false;
            var     viewModel     = new ShoppingScreenViewModel();
            Dictionary <int, Product> indexedProducts  = new Dictionary <int, Product>();
            ProductServices           productServices  = new ProductServices();
            ShoppingServices          shoppingServices = new ShoppingServices();

            while (!wantsToExit)
            {
                Console.Clear();
                Console.WriteLine("Welcome {0} to the rare and custom items's shop!\nBelow is a list of all products currently available.", user.UserName);

                indexedProducts.Clear();

                var allProducts = viewModel.AllProdcuts;
                for (int productCount = 0; productCount < allProducts.Count; productCount++)
                {
                    var currenProduct = allProducts[productCount];
                    indexedProducts.Add(productCount, currenProduct);
                }

                Console.WriteLine("Available items: \n");
                foreach (var indexedProduct in indexedProducts)
                {
                    if (!indexedProduct.Value.IsPurchased)
                    {
                        Console.WriteLine($"{indexedProduct.Key} - {indexedProduct.Value.ProductName}");
                    }

                    continue;
                }

                Console.WriteLine("Sold items: \n");
                foreach (var indexedProduct in indexedProducts)
                {
                    if (indexedProduct.Value.IsPurchased)
                    {
                        Console.WriteLine($"{indexedProduct.Key} - {indexedProduct.Value.ProductName} - {indexedProduct.Value.Owner.UserName}");
                    }

                    continue;
                }

                Console.WriteLine("\n\nPlease select from the above list which item you would like to buy or press e and enter to go back a page: ");

                Product selectedProduct;

                try{
                    var input = Console.ReadLine();
                    if (input[0] == 'e')
                    {
                        wantsToExit = true;
                        break;
                    }
                    userSelection   = int.Parse(input);
                    selectedProduct = indexedProducts[userSelection];
                }
                catch (Exception e) {
                    Console.WriteLine("Sorry could not read input either as it is an invalid input or the product does not exist: " + e.Message);
                    Trace.TraceError("Incorrect input format", e.Message + e.StackTrace, SeverityLevel.Error);
                    continue;
                }

                Console.Clear();
                Console.WriteLine("Name: {0}\nPrice: £{1}\nIs it on sale: {2}\n\n", selectedProduct.ProductName, selectedProduct.ProductPrice, selectedProduct.IsSalesProduct ? "Yes" : "No");
                Console.WriteLine("Would you like to buy? (y, n)");

                var doesBuy = Console.ReadLine()[0];
                if (doesBuy != 'y' && doesBuy != 'n')
                {
                    Console.WriteLine("Sorry, invalid input");
                    Console.ReadLine();
                    continue;
                }

                if (doesBuy == 'n')
                {
                    continue;
                }

                if (viewModel.PurchaseProduct(user, selectedProduct))
                {
                    Console.WriteLine("Purchase successful");
                    Console.ReadLine();
                    continue;
                }
            }
        }