Ejemplo n.º 1
0
        /// <summary>
        /// Creates the object of rice.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="weight">The weight.</param>
        /// <param name="price">The price.</param>
        public static void CreateObjectOfRice(string name, double weight, double price)
        {
            RiceClass      rice           = new RiceClass(name, weight, price);
            InventeryTypes inventeryTypes = InventeryFactory.ReadJsonFile();

            inventeryTypes.RiceList.Add(rice);
            WriteToFile.WriteDataToFile(inventeryTypes);
            Console.WriteLine("data successfully added");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the wheat object.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="weight">The weight.</param>
        /// <param name="price">The price.</param>
        public static void CreateWheatObject(string name, double weight, double price)
        {
            WheatClass     wheat          = new WheatClass(name, weight, price);
            InventeryTypes inventeryTypes = InventeryFactory.ReadJsonFile();

            inventeryTypes.WheatList.Add(wheat);
            WriteToFile.WriteDataToFile(inventeryTypes);
            Console.WriteLine("added data to the inventery successful");
        }
Ejemplo n.º 3
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    pulses         = new PulsesClass(name, weight, pricePerKg);
            InventeryTypes inventeryTypes = InventeryFactory.ReadJsonFile();

            inventeryTypes.PulsesList.Add(pulses);
            WriteToFile.WriteDataToFile(inventeryTypes);
            Console.WriteLine("added data to inventory successfully");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Removes the specified item name.
        /// </summary>
        /// <param name="itemName">Name of the item.</param>
        public static void RemoveRiceObject(string itemName)
        {
            InventeryTypes   inventeryType = InventeryFactory.ReadJsonFile();
            List <RiceClass> riceList      = inventeryType.RiceList;

            foreach (RiceClass riceName in riceList)
            {
                if (riceName.Name.Equals(itemName))
                {
                    riceList.Remove(riceName);
                    WriteToFile.WriteDataToFile(inventeryType);
                    Console.WriteLine("item " + itemName + " has been removed from your list");
                    return;
                }
            }

            Console.WriteLine("item " + itemName + " not found in list");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Removes the wheat object.
        /// </summary>
        /// <param name="itemName">Name of the item.</param>
        public static void RemoveWheatObject(string itemName)
        {
            InventeryTypes    inventeryTypes = InventeryFactory.ReadJsonFile();
            List <WheatClass> wheatList      = inventeryTypes.WheatList;

            foreach (WheatClass wheat in wheatList)
            {
                if (wheat.Name.Equals(itemName))
                {
                    wheatList.Remove(wheat);
                    WriteToFile.WriteDataToFile(inventeryTypes);
                    Console.WriteLine("item " + itemName + "Removed successfuly");
                    Console.WriteLine("---------------------");
                    return;
                }
            }

            Console.WriteLine("item " + itemName + " to be removed is not found");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Removes the pulses object.
        /// </summary>
        /// <param name="itemName">Name of the item.</param>
        public static void RemovePulsesObject(string itemName)
        {
            InventeryTypes     inventoryTypes = InventeryFactory.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");
        }
Ejemplo n.º 7
0
        /// <summary>
        /// changing the name of paritcular object
        /// </summary>
        /// <param name="inventeryType"></param>
        /// <param name="itemName"></param>
        public static void ChangeName(string inventeryType, string itemName)
        {
            string newName;

            while (true)
            {
                Console.WriteLine("enter the new name for " + inventeryType);
                newName = Console.ReadLine();
                if (Utility.ContainsCharacter(newName))
                {
                    Console.WriteLine("character not allowed");
                    continue;
                }

                if (Utility.ContainsDigit(newName))
                {
                    Console.WriteLine("digits not allowed");
                    continue;
                }

                if (Utility.CheckString(newName))
                {
                    Console.WriteLine("you should specify name");
                    continue;
                }

                InventeryTypes inventeryTypes = InventeryFactory.ReadJsonFile();
                if (inventeryType.Equals("RICE"))
                {
                    List <RiceClass> riceList = inventeryTypes.RiceList;
                    foreach (RiceClass riceName in riceList)
                    {
                        if (riceName.Name.Equals(itemName))
                        {
                            riceName.Name = newName;
                            break;
                        }
                    }

                    WriteToFile.WriteDataToFile(inventeryTypes);
                    Console.WriteLine("data uploaded sussfully");
                }

                if (inventeryType.Equals("WHEAT"))
                {
                    List <WheatClass> wheatList = inventeryTypes.WheatList;
                    foreach (WheatClass wheatName in wheatList)
                    {
                        if (wheatName.Name.Equals(itemName))
                        {
                            wheatName.Name = newName;
                            break;
                        }
                    }

                    WriteToFile.WriteDataToFile(inventeryTypes);
                    Console.WriteLine("data uploaded successfuly");
                }

                if (inventeryType.Equals("PULSES"))
                {
                    List <PulsesClass> pulsesList = inventeryTypes.PulsesList;
                    foreach (PulsesClass pulsesName in pulsesList)
                    {
                        if (pulsesName.Name.Equals(itemName))
                        {
                            pulsesName.Name = newName;
                            break;
                        }
                    }

                    WriteToFile.WriteDataToFile(inventeryTypes);
                    Console.WriteLine("data uploaded successfully");
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// changing the price of particular object
        /// </summary>
        /// <param name="inventeryTypes"></param>
        /// <param name="itemName"></param>
        public static void ChangePrice(string inventeryType, string itemName)
        {
            double         newPricePerKG;
            InventeryTypes inventeryTypes = InventeryFactory.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 (inventeryType.Equals("RICE"))
            {
                List <RiceClass> riceList = inventeryTypes.RiceList;

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

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

            if (inventeryType.Equals("WHEAT"))
            {
                List <WheatClass> wheatList = inventeryTypes.WheatList;

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

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

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

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

                WriteToFile.WriteDataToFile(inventeryTypes);
                Console.WriteLine("Updated successfully");
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// changing the weight of particular object
        /// </summary>
        /// <param name="inventeryType"></param>
        /// <param name="itemName"></param>
        public static void ChangeWeight(string inventeryType, string itemName)
        {
            double         newWeight;
            InventeryTypes inventeryTypes = InventeryFactory.ReadJsonFile();

            while (true)
            {
                Console.WriteLine("Enter the Weight");
                string stringWeight = Console.ReadLine();

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

            if (inventeryType.Equals("RICE"))
            {
                List <RiceClass> riceList = inventeryTypes.RiceList;
                foreach (RiceClass riceName in riceList)
                {
                    if (riceName.Name.Equals(itemName))
                    {
                        riceName.Weight = newWeight;
                        break;
                    }
                }

                WriteToFile.WriteDataToFile(inventeryTypes);
                Console.WriteLine("data uploaded successfully");
            }

            if (inventeryType.Equals("WHEAT"))
            {
                List <WheatClass> wheatList = inventeryTypes.WheatList;
                foreach (WheatClass wheat in wheatList)
                {
                    if (wheat.Name.Equals(itemName))
                    {
                        wheat.Weight = newWeight;
                        break;
                    }
                }

                WriteToFile.WriteDataToFile(inventeryTypes);
                Console.WriteLine("data uploaded successfully");
            }

            if (inventeryType.Equals("PULSES"))
            {
                List <PulsesClass> pulsesList = inventeryTypes.PulsesList;
                foreach (PulsesClass pulses in pulsesList)
                {
                    if (pulses.Name.Equals(itemName))
                    {
                        pulses.Weight = newWeight;
                        break;
                    }
                }

                WriteToFile.WriteDataToFile(inventeryTypes);
                Console.WriteLine("data uploaded successfully");
            }
        }