Exemplo n.º 1
0
        /// <summary>
        /// Takes input from user to create objects
        /// </summary>
        /// <param name="inventoryType">inventory Type</param>
        public static void TakeInputsForCreatingObject(string inventoryType)
        {
            string name       = null;
            double weight     = 0;
            double pricePerKG = 0;

            ////Validate name entered by user
            while (true)
            {
                Console.WriteLine("\nEnter the Name for " + inventoryType);
                name = Console.ReadLine();

                if (InventoryMngtUtility.ContainsCharacter(name))
                {
                    Console.WriteLine("\nCharacter not allowed");
                    continue;
                }

                if (InventoryMngtUtility.ContainsDigit(name))
                {
                    Console.WriteLine("\nDigits not allowed");
                    continue;
                }

                if (InventoryMngtUtility.CheckString(name))
                {
                    Console.WriteLine("\nYou should Specify a name");
                    continue;
                }

                break;
            }

            ////Validate weight entered by user
            while (true)
            {
                Console.WriteLine("\nEnter the Weight");
                string stringWeight = Console.ReadLine();

                try
                {
                    weight = Convert.ToDouble(stringWeight);
                    break;
                }
                catch (Exception)
                {
                    Console.WriteLine("\nInvalid Input For Weight");
                    continue;
                }
            }

            ////Validate price entered by user
            while (true)
            {
                Console.WriteLine("\nSpecify Price per Kg");
                string stringPrice = Console.ReadLine();
                try
                {
                    pricePerKG = Convert.ToDouble(stringPrice);
                    break;
                }
                catch (Exception)
                {
                    Console.WriteLine("\nInvalid Input For Price Per KG");
                    continue;
                }
            }

            //// Checks For Which Inventory Item Object should be created.
            if (inventoryType.Equals("RICE"))
            {
                Rice.CreateRiceObject(name, weight, pricePerKG);
            }

            //// Checks For Which Inventory Item Object should be created.
            if (inventoryType.Equals("WHEAT"))
            {
                Wheat.CreateWheatObject(name, weight, pricePerKG);
            }

            //// Checks For Which Inventory Item Object should be created.
            if (inventoryType.Equals("PULSES"))
            {
                Pulses.CreatePulsesObject(name, weight, pricePerKG);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Makes the changes.
        /// </summary>
        /// <param name="inventoryType">Type of the inventory.</param>
        /// <param name="itemName">Name of the item.</param>
        public static void ChangeName(string inventoryType, string itemName)
        {
            string newName;

            while (true)
            {
                Console.WriteLine("\nEnter the New name for " + inventoryType);
                newName = Console.ReadLine();

                if (InventoryMngtUtility.ContainsCharacter(newName))
                {
                    Console.WriteLine("\nNo Character Allowed");
                    continue;
                }

                if (InventoryMngtUtility.ContainsDigit(newName))
                {
                    Console.WriteLine("\nNo Digits Allowed");
                    continue;
                }

                if (InventoryMngtUtility.CheckString(newName))
                {
                    Console.WriteLine("\nYou should Specify a name");
                    continue;
                }

                break;
            }

            InventoryStructure inventoryTypes = InventoryFactory.ReadJsonFile();

            if (inventoryType.Equals("RICE"))
            {
                List <Rice> riceList = inventoryTypes.RiceList;

                foreach (Rice rice in riceList)
                {
                    if (rice.Name.Equals(itemName))
                    {
                        rice.Name = newName;
                        break;
                    }
                }

                InventoryMngtUtility.WriteToFile(inventoryTypes);
                Console.WriteLine("\nUpdated successfully");
            }

            if (inventoryType.Equals("WHEAt"))
            {
                List <Wheat> wheatList = inventoryTypes.WheatList;

                foreach (Wheat wheat in wheatList)
                {
                    if (wheat.Name.Equals(itemName))
                    {
                        wheat.Name = newName;
                        break;
                    }
                }

                InventoryMngtUtility.WriteToFile(inventoryTypes);
                Console.WriteLine("\nUpdated successfully");
            }

            if (inventoryType.Equals("PULSES"))
            {
                List <Pulses> pulseList = inventoryTypes.PulsesList;

                foreach (Pulses pulse in pulseList)
                {
                    if (pulse.Name.Equals(itemName))
                    {
                        pulse.Name = newName;
                        break;
                    }
                }

                InventoryMngtUtility.WriteToFile(inventoryTypes);
                Console.WriteLine("\nUpdated successfully");
            }
        }