Exemple #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");
        }
Exemple #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");
        }
Exemple #3
0
        /// <summary>
        /// Does the object exist.
        /// </summary>
        /// <param name="itemName">Name of the item.</param>
        /// <returns>returns true or false</returns>
        public static bool DoesObjectExist(string itemName)
        {
            InventoryTypes    inventoryTypes = InventoryFactory.ReadJsonFile();
            List <WheatClass> wheatList      = inventoryTypes.WheatList;

            foreach (WheatClass wheat in wheatList)
            {
                if (wheat.Name.Equals(itemName))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #4
0
        /// <summary>
        /// Does the object exist.
        /// </summary>
        /// <param name="itemName">Name of the item.</param>
        /// <returns>returns true or false</returns>
        public static bool DoesObjectExist(string itemName)
        {
            InventoryTypes     inventoryTypes = InventoryFactory.ReadJsonFile();
            List <PulsesClass> pulseList      = inventoryTypes.PulsesList;

            foreach (PulsesClass pulse in pulseList)
            {
                if (pulse.Name.Equals(itemName))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #5
0
        /// <summary>
        /// Does the object exist.
        /// </summary>
        /// <param name="itemName">Name of the item.</param>
        /// <returns>returns true or false</returns>
        public static bool DoesObjectExist(string itemName)
        {
            InventoryTypes   inventoryTypes = InventoryFactory.ReadJsonFile();
            List <RiceClass> riceList       = inventoryTypes.RiceList;

            foreach (RiceClass rice in riceList)
            {
                if (rice.Name.Equals(itemName))
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Gets the inventory list.
        /// </summary>
        /// <param name="inventoryType">Type of the inventory.</param>
        public static void GetInventoryList(string inventoryType)
        {
            ////Getting Inventory Objects from the inventory factory.
            InventoryTypes inventoryTypes = InventoryFactory.ReadJsonFile();

            if (inventoryType.Equals("RICE"))
            {
                List <RiceClass> riceList = inventoryTypes.RiceList;
                foreach (RiceClass rice in riceList)
                {
                    Console.WriteLine("Rice type");
                    Console.WriteLine("Name : " + rice.Name + "\nWeight : " + rice.Weight + "\nPrice per Kg : " + rice.PricePerKg);
                    Console.WriteLine("Total price of " + rice.Name + " = " + (rice.Weight * rice.PricePerKg));
                    Console.WriteLine("------------------------------------------");
                }

                return;
            }

            if (inventoryType.Equals("WHEAT"))
            {
                List <WheatClass> wheatList = inventoryTypes.WheatList;
                foreach (WheatClass wheat in wheatList)
                {
                    Console.WriteLine("Wheat type");
                    Console.WriteLine("Name : " + wheat.Name + "\nWeight : " + wheat.Weight + "\nPrice per Kg : " + wheat.PricePerKg);
                    Console.WriteLine("Total price of " + wheat.Name + " = " + (wheat.Weight * wheat.PricePerKg));
                    Console.WriteLine("------------------------------------------");
                }

                return;
            }

            if (inventoryType.Equals("PULSES"))
            {
                List <PulsesClass> pulsesList = inventoryTypes.PulsesList;
                foreach (PulsesClass pulse in pulsesList)
                {
                    Console.WriteLine("Pulse type");
                    Console.WriteLine("Name : " + pulse.Name + "\nWeight : " + pulse.Weight + "\nPrice per Kg : " + pulse.PricePerKg);
                    Console.WriteLine("Total price of " + pulse.Name + " = " + (pulse.Weight * pulse.PricePerKg));
                    Console.WriteLine("------------------------------------------");
                }
            }
        }
Exemple #7
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");
        }
Exemple #8
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");
        }
Exemple #9
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");
            }
        }