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)
        {
            Pulses             pulse          = new Pulses(name, weight, pricePerKG);
            InventoryStructure inventoryTypes = InventoryFactory.ReadJsonFile();

            inventoryTypes.PulsesList.Add(pulse);
            InventoryMngtUtility.WriteToFile(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)
        {
            Wheat wheat = new Wheat(name, weight, pricePerKG);
            InventoryStructure inventoryTypes = InventoryFactory.ReadJsonFile();

            inventoryTypes.WheatList.Add(wheat);
            InventoryMngtUtility.WriteToFile(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)
        {
            InventoryStructure inventoryTypes = InventoryFactory.ReadJsonFile();
            List <Wheat>       wheatList      = inventoryTypes.WheatList;

            foreach (Wheat 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)
        {
            InventoryStructure inventoryTypes = InventoryFactory.ReadJsonFile();
            List <Pulses>      pulseList      = inventoryTypes.PulsesList;

            foreach (Pulses 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)
        {
            InventoryStructure inventoryTypes = InventoryFactory.ReadJsonFile();
            List <Rice>        riceList       = inventoryTypes.RiceList;

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

            return(false);
        }
Exemple #6
0
        /// <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.
            InventoryStructure inventoryTypes = InventoryFactory.ReadJsonFile();

            ////Print details of type choosen by user
            if (inventoryType.Equals("RICE"))
            {
                List <Rice> riceList = inventoryTypes.RiceList;
                foreach (Rice rice in riceList)
                {
                    Console.WriteLine("\nRice 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 <Wheat> wheatList = inventoryTypes.WheatList;
                foreach (Wheat wheat in wheatList)
                {
                    Console.WriteLine("\nWheat 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 <Pulses> pulsesList = inventoryTypes.PulsesList;
                foreach (Pulses 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)
        {
            InventoryStructure inventoryTypes = InventoryFactory.ReadJsonFile();
            List <Wheat>       wheatList      = inventoryTypes.WheatList;

            foreach (Wheat wheat in wheatList)
            {
                if (wheat.Name.Equals(itemName))
                {
                    wheatList.Remove(wheat);
                    InventoryMngtUtility.WriteToFile(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)
        {
            InventoryStructure inventoryTypes = InventoryFactory.ReadJsonFile();
            List <Rice>        riceList       = inventoryTypes.RiceList;

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

            Console.WriteLine("Item " + itemName + " to be removed is not present...");
        }
Exemple #9
0
        /// <summary>
        /// Removes the pulses object.
        /// </summary>
        /// <param name="itemName">Name of the item.</param>
        public static void RemovePulseObject(string itemName)
        {
            InventoryStructure inventoryTypes = InventoryFactory.ReadJsonFile();
            List <Pulses>      pulseList      = inventoryTypes.PulsesList;

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

                    return;
                }
            }

            Console.WriteLine("Item " + itemName + "to be removed not found");
        }
Exemple #10
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");
            }
        }
Exemple #11
0
        /// <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;
            InventoryStructure inventoryTypes = InventoryFactory.ReadJsonFile();

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

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

                foreach (Rice rice in riceList)
                {
                    if (rice.Name.Equals(itemName))
                    {
                        rice.PricePerKg = newPricePerKG;
                        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.PricePerKg = newPricePerKG;
                        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.PricePerKg = newPricePerKG;
                        break;
                    }
                }

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