static OrderDetalis GetInput() { bool IsCorrect = true; while (IsCorrect == true) { Console.Write("Product Id: "); var ProductIdString = Console.ReadLine(); Console.Write("Amount: "); var QuantityString = Console.ReadLine(); int ProductId; bool parseSuccess = int.TryParse(ProductIdString, out ProductId); bool parseSuccessTwo = int.TryParse(QuantityString, out int Quantity); if (parseSuccess & parseSuccessTwo) { var orderDetalis = new OrderDetalis(OrderId, ProductId, Quantity); return(orderDetalis); } else { Console.WriteLine("This is not a number, try again!"); IsCorrect = true; continue; } } return(null); }
static bool CheckLessThanZero(IProductsRepository product, OrderDetalis order) { if (Int32.Parse(product.GetAmount(order)) - order.Amount < 0) { Console.WriteLine("We don't have enough items in stock change amount"); return(true); } else { return(false); } }
static bool IsProductIdInBase(IProductsRepository product, OrderDetalis product_id) { if (!product.GetAllProductId().Contains(product_id.product_id)) { Console.WriteLine("There is no such id in base, try again!"); return(false); } else { return(true); } }
internal static bool MainMenu(IOrdersRepository order, IProductsRepository product, IOrderDetalisRepository orderDetalis) { Console.Clear(); OrdersView.PrintMenu(CustomerId, OrderId); switch (Console.ReadLine()) { case "6": order.UpdateOrder(UpdateStatus(1)); GetIdAndAmount(orderDetalis.GetAllOrdersDetalis(OrderId), product); GetNewOrderInput(order); return(true); case "1": Console.Clear(); ProductsView.printList(product.GetAllProducts()); bool ProductInBase = true; var addorder = new OrderDetalis(OrderId); while (ProductInBase) { addorder = GetInput(); if (IsProductIdInBase(product, addorder)) { ProductInBase = CheckLessThanZero(product, addorder); } else { ProductInBase = true; } } if (orderDetalis.AddOrderDetalis(addorder) == true) { OrdersView.AddedSuccessfully(); } var updateProduct = new Products(addorder.product_id, addorder.Amount); product.UpdateProduct(updateProduct); orderDetalis.UpdatePrice(addorder); return(true); case "2": Console.Clear(); GetOrderList(orderDetalis); OrdersView.PressAnyKey(); return(true); case "3": if (!IsAnyProductInBase(orderDetalis)) { Console.WriteLine("Buy something first"); OrdersView.PressAnyKey(); } else { Console.Clear(); GetOrderList(orderDetalis); var updateDetalis = GetInput(); var amount = orderDetalis.GetCurrentAmount(updateDetalis); product.UpdateProductUp(amount); orderDetalis.UpdateOrderDetalis(updateDetalis); orderDetalis.UpdatePrice(updateDetalis); var updateAmount = new Products(updateDetalis.product_id, updateDetalis.Amount); product.UpdateProduct(updateAmount); return(true); } return(true); case "4": GetIdAndAmount(orderDetalis.GetAllOrdersDetalis(OrderId), product); orderDetalis.DeleteOrderDetalis(OrderId); return(true); case "5": bool showMenu = true; while (showMenu) { showMenu = getPay(order); } return(true); case "0": GetIdAndAmount(orderDetalis.GetAllOrdersDetalis(OrderId), product); order.UpdateOrder(UpdateStatus(1)); return(false); default: Console.WriteLine("There is no such choice"); OrdersView.PressAnyKey(); return(true); } }