Ejemplo n.º 1
0
        private void AddBatch()
        {
            try
            {
                bool batchType        = InputBatchType();
                var  productsQuantity = new Dictionary <int, double>();

                while (true)
                {
                    Console.Clear();
                    Console.WriteLine("Products:\n");
                    DisplayNotSelectedProducts(productsQuantity);
                    Console.WriteLine("\nSelected products for a batch:\n");
                    DisplaySelectedProducts(productsQuantity);
                    Console.Write("\nEnter new product's id to add to a batch " +
                                  "(or -e to end adding new products): ");
                    string productIdStr = Console.ReadLine();

                    if (productIdStr == "-e")
                    {
                        break;
                    }

                    int productId = Convert.ToInt32(productIdStr);
                    var product   = _storageController.FindProduct(productId);
                    Console.Write($"Enter qunatity of {product.Name}: ");
                    double productQuantity = Convert.ToDouble(Console.ReadLine());

                    if (productsQuantity.ContainsKey(productId))
                    {
                        productsQuantity[productId] += productQuantity;
                    }
                    else
                    {
                        productsQuantity.Add(productId, productQuantity);
                    }
                }

                if (productsQuantity.Count != 0)
                {
                    _storageController.AddBatch(batchType, productsQuantity);
                    Console.WriteLine("\nSelected products was successfully added to the new batch.");
                    Console.Write("\nPress any button to continue...");
                    Console.ReadKey();
                }
            }
            catch (BackToMenuException)
            {
                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nAn error ocures during adding process.");
                Console.WriteLine(ex.Message);
                Console.Write("\nPress any button to continue...");
                Console.ReadKey();
            }
        }