예제 #1
0
        /// <summary>
        /// This method is to return a boolean value every time there is a 'Y/N' Operation for validating the entry.
        /// </summary>
        /// <param name="strMessage">This is the message that the console will print in the console</param>
        /// <param name="myRepoLayer">Our Repository Layer to access into the Database.</param>
        /// <returns>Returns a true when the Option selected is 'Y', else, a false.</returns>
        private static bool ValidateIfUserWantToRedoAction(string strMessage, P0_RLayer myRepoLayer)
        {
            Console.WriteLine(strMessage);
            string strUIUserChoice = Console.ReadLine();

            if (myRepoLayer.ChangeLocationBranch(strUIUserChoice)) //Y
            {
                return(true);
            }
            else //N
            {
                return(false);
            }
        }
예제 #2
0
        /// <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
        }