示例#1
0
        /// <summary>
        /// Creates the pulses object.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="weight">The weight.</param>
        /// <param name="pricePerKG">The price per kg.</param>
        public static void CreatePulsesObject(string name, double weight, double pricePerKG)
        {
            PulsesClass    pulse          = new PulsesClass(name, weight, pricePerKG);
            InventoryTypes inventoryTypes = InventoryFactory.ReadJsonFile();

            inventoryTypes.PulsesList.Add(pulse);
            WriteToFile.WriteDataToFile(inventoryTypes);
            Console.WriteLine("Added To inventory Succefully");
        }
示例#2
0
        /// <summary>
        /// Creates the wheat object.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="weight">The weight.</param>
        /// <param name="pricePerKG">The price per kg.</param>
        public static void CreateWheatObject(string name, double weight, double pricePerKG)
        {
            WheatClass     wheat          = new WheatClass(name, weight, pricePerKG);
            InventoryTypes inventoryTypes = InventoryFactory.ReadJsonFile();

            inventoryTypes.WheatList.Add(wheat);
            WriteToFile.WriteDataToFile(inventoryTypes);
            Console.WriteLine("Added To inventory Succefully");
        }
示例#3
0
        /// <summary>
        /// Removes the wheat object.
        /// </summary>
        /// <param name="itemName">Name of the item.</param>
        public static void RemoveWheatObject(string itemName)
        {
            InventoryTypes    inventoryTypes = InventoryFactory.ReadJsonFile();
            List <WheatClass> wheatList      = inventoryTypes.WheatList;

            foreach (WheatClass wheat in wheatList)
            {
                if (wheat.Name.Equals(itemName))
                {
                    wheatList.Remove(wheat);
                    WriteToFile.WriteDataToFile(inventoryTypes);
                    Console.WriteLine("Item " + itemName + "removed Successfully");
                    Console.WriteLine("--------------------------------------------");
                    return;
                }
            }

            Console.WriteLine("Item " + itemName + "to be removed not found");
        }
示例#4
0
        /// <summary>
        /// Removes the rice object.
        /// </summary>
        /// <param name="itemName">Name of the item.</param>
        public static void RemoveRiceObject(string itemName)
        {
            InventoryTypes   inventoryTypes = InventoryFactory.ReadJsonFile();
            List <RiceClass> riceList       = inventoryTypes.RiceList;

            foreach (RiceClass rice in riceList)
            {
                if (rice.Name.Equals(itemName))
                {
                    riceList.Remove(rice);
                    WriteToFile.WriteDataToFile(inventoryTypes);
                    Console.WriteLine("Item " + itemName + "removed Successfully");
                    Console.WriteLine("--------------------------------------------");
                    return;
                }
            }

            Console.WriteLine("Item " + itemName + "to be removed not found");
        }
示例#5
0
        /// <summary>
        /// Removes the pulse object.
        /// </summary>
        /// <param name="itemName">Name of the item.</param>
        public static void RemovePulseObject(string itemName)
        {
            InventoryTypes     inventoryTypes = InventoryFactory.ReadJsonFile();
            List <PulsesClass> pulseList      = inventoryTypes.PulsesList;

            foreach (PulsesClass pulse in pulseList)
            {
                if (pulse.Name.Equals(itemName))
                {
                    pulseList.Remove(pulse);
                    WriteToFile.WriteDataToFile(inventoryTypes);
                    Console.WriteLine("Item " + itemName + "removed Successfully");
                    Console.WriteLine("--------------------------------------------");

                    return;
                }
            }

            Console.WriteLine("Item " + itemName + "to be removed not found");
        }
        /// <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("Enter the New name for " + inventoryType);
                newName = Console.ReadLine();

                if (Utility.ContainsCharacter(newName))
                {
                    Console.WriteLine("No Character Allowed");
                    continue;
                }

                if (Utility.ContainsDigit(newName))
                {
                    Console.WriteLine("No Digits Allowed");
                    continue;
                }

                if (Utility.CheckString(newName))
                {
                    Console.WriteLine("You should Specify a name");
                    continue;
                }

                break;
            }

            InventoryTypes inventoryTypes = InventoryFactory.ReadJsonFile();

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

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

                WriteToFile.WriteDataToFile(inventoryTypes);
                Console.WriteLine("Updated successfully");
            }

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

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

                WriteToFile.WriteDataToFile(inventoryTypes);
                Console.WriteLine("Updated successfully");
            }

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

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

                WriteToFile.WriteDataToFile(inventoryTypes);
                Console.WriteLine("Updated successfully");
            }
        }
        /// <summary>
        /// Changes the price.
        /// </summary>
        /// <param name="inventoryType">Type of the inventory.</param>
        /// <param name="itemName">Name of the item.</param>
        public static void ChangePrice(string inventoryType, string itemName)
        {
            double         newPricePerKG;
            InventoryTypes inventoryTypes = InventoryFactory.ReadJsonFile();

            while (true)
            {
                Console.WriteLine("Specify Price per Kg");
                string stringPrice = Console.ReadLine();
                try
                {
                    newPricePerKG = Convert.ToDouble(stringPrice);
                    break;
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid Input For Price Per KG");
                    continue;
                }
            }

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

                foreach (RiceClass rice in riceList)
                {
                    if (rice.Name.Equals(itemName))
                    {
                        rice.PricePerKg = newPricePerKG;
                        break;
                    }
                }

                WriteToFile.WriteDataToFile(inventoryTypes);
                Console.WriteLine("Updated successfully");
            }

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

                foreach (WheatClass wheat in wheatList)
                {
                    if (wheat.Name.Equals(itemName))
                    {
                        wheat.PricePerKg = newPricePerKG;
                        break;
                    }
                }

                WriteToFile.WriteDataToFile(inventoryTypes);
                Console.WriteLine("Updated successfully");
            }

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

                foreach (PulsesClass pulse in pulseList)
                {
                    if (pulse.Name.Equals(itemName))
                    {
                        pulse.PricePerKg = newPricePerKG;
                        break;
                    }
                }

                WriteToFile.WriteDataToFile(inventoryTypes);
                Console.WriteLine("Updated successfully");
            }
        }