/// <summary> /// This method is for adding manually some products into the Store Inventory. If a product is already registered, it will link the already created product and add a /// new store inventory. /// </summary> /// <param name="myRepoLayer">Our Repository Layer to access into the Database.</param> private static void AddOrUpdateProductInventoryInLocation(P0_RLayer myRepoLayer) { bool bolUILocationSelected = true; int intLocationID = 0; do { Console.Write($"{myRepoLayer.ListEveryLocation()}\nSelect the LocationID to view the Inventory of the store : "); string strLocationID = Console.ReadLine(); intLocationID = myRepoLayer.LocationHistoryVerification(strLocationID); if (intLocationID != 0) { bolUILocationSelected = false; } else { Console.WriteLine("\t\tInvalid option\n"); } } while (bolUILocationSelected); bool bolUIInventory = true; do { //GetAllProductsFromInventory Console.Write($"\t\t\tInventory: \n{myRepoLayer.GetAllProductsFromInventory(intLocationID)}\n\nSelect the product to modify (Input A to add a new product):"); string strUIProductID = Console.ReadLine(); if (strUIProductID.ToLower() == "a") { // Add a new product string strName = "", strDescription = ""; double dblPrice = 0; int intQuantity = 0; Console.WriteLine("Name of the product: "); strName = Console.ReadLine(); Console.WriteLine("Description fo the product: "); strDescription = Console.ReadLine(); bool bolUIPriceAndQty = true; do { Console.WriteLine("The price for the product: "); if (!double.TryParse(Console.ReadLine(), out dblPrice)) { Console.WriteLine("Invalid Input\n"); continue; } else { bolUIPriceAndQty = false; } }while (bolUIPriceAndQty); bolUIPriceAndQty = true; do { Console.WriteLine("The quantity for the product: "); if (!int.TryParse(Console.ReadLine(), out intQuantity)) { Console.WriteLine("Invalid Input\n"); continue; } else { bolUIPriceAndQty = false; } }while (bolUIPriceAndQty); //Add the product into the inventory in the store intLocationID try { myRepoLayer.AddProductIntoStoreInventory(intLocationID, strName, strDescription, dblPrice, intQuantity); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } } else if (myRepoLayer.SearchProductWithID(strUIProductID)) { bool bolUIQuantity = true; do { Console.Write("Quantity: "); string strInventoryQuantity = Console.ReadLine(); int intQuantity = 0; /// if (!int.TryParse(strInventoryQuantity, out intQuantity)) { Console.WriteLine("\t\tInvalid input for quantity."); continue; } try { myRepoLayer.SetProductFromInventory(int.Parse(strUIProductID), intQuantity); bolUIQuantity = false; } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } } while (bolUIQuantity); } else { Console.WriteLine("Invalid input\n"); continue;// } if (ValidateIfUserWantToRedoAction("Add or update another product?: \nY/N", myRepoLayer)) { continue; } else //N { bolUIInventory = false; } } while (bolUIInventory); }
/// <summary> /// This method implements the main functionality of generating order for the logged customer depending of the registered location. /// </summary> /// <param name="myRepoLayer">Our Repository Layer to access into the Database.</param> private static void GenerateOrder(P0_RLayer myRepoLayer) { #region GenerateOrder #region ChangeLocation Console.WriteLine($"Your default location is {myRepoLayer.GetActualLocation()}, stay in the location?\nY/N"); string strUIChanceLocation = Console.ReadLine(); bool bolUILocation = true; bool bolUIInventory = true; do { // Check if the selection is correct if (strUIChanceLocation.Trim().Length != 1) { Console.WriteLine("Invalid input\nY/N\n"); strUIChanceLocation = Console.ReadLine(); continue; } if (myRepoLayer.ChangeLocationBranch(strUIChanceLocation)) { // Stay in the location bolUILocation = false; } else { //Change into another location bool bolUILocationSelected = true; do { Console.Write($"{myRepoLayer.ListEveryLocationExceptCustomerLocation()}\nSelect the LocationID to change into the location: "); string strUILocation = Console.ReadLine(); if (myRepoLayer.LocationChangeVerification(strUILocation)) { bolUILocationSelected = false; } else { Console.WriteLine("\t\tInvalid option\n"); } } while (bolUILocationSelected); bolUILocation = false; } } while (bolUILocation); #endregion do { Console.Write($"\t\t\tInventory: \n{myRepoLayer.ListAllInventoryInLocation()}\n\nSelect the product to add into the order:"); string strUIProductID = Console.ReadLine(); if (myRepoLayer.SearchProductWithID(strUIProductID)) { bool bolUIQuantity = true; do { Console.Write("Quantity: "); string strInventoryQuantity = Console.ReadLine(); int intQuantity = 0; /// if (!int.TryParse(strInventoryQuantity, out intQuantity)) { Console.WriteLine("\t\tInvalid input for quantity."); continue; } try { myRepoLayer.SetOrderForCustomer(int.Parse(strUIProductID), intQuantity); bolUIQuantity = false; } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } } while (bolUIQuantity); if (ValidateIfUserWantToRedoAction("Add another product?: \nY/N", myRepoLayer)) { continue; } else //N { bolUIInventory = false; } } else { Console.WriteLine("Invalid input\n"); continue;// } } while (bolUIInventory); // Mostrar el total de la orden y guardar en DB Console.WriteLine(myRepoLayer.PrintOrder()); #endregion }