Beispiel #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");
        }
Beispiel #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");
        }
Beispiel #3
0
        /// <summary>
        /// Inventories the menu view.
        /// </summary>
        /// <param name="inventoryType">Type of the inventory.</param>
        public static void InventoryMenuview(string inventoryType)
        {
            int option = 0;

            while (true)
            {
                Console.WriteLine("--------------------------------------------");
                Console.WriteLine("1.To view Existing Inventory for " + inventoryType);
                Console.WriteLine("2.To Remove an " + inventoryType + " Item");
                Console.WriteLine("3.To Add " + inventoryType + " Item");
                Console.WriteLine("4.To Edit from Existing " + inventoryType + " Inventory");

                string stringOption = Console.ReadLine();

                if (InventoryMngtUtility.IsNumber(stringOption) == false)
                {
                    Console.WriteLine("Invalid input");
                    continue;
                }

                option = Convert.ToInt32(stringOption);

                //// Calls the mdethods based on the Option Choosen
                switch (option)
                {
                case 1:
                    InventoryManager.GetInventoryList(inventoryType);
                    break;

                case 2:
                    InputForInventory.TakeInputForRemovingObject(inventoryType);
                    break;

                case 3:
                    InputForInventory.TakeInputsForCreatingObject(inventoryType);
                    break;

                case 4:
                    InventoryManipulationMenu.InventoryManipulationview(inventoryType);
                    break;

                default:
                    return;
                }
            }
        }
Beispiel #4
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");
        }
Beispiel #5
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...");
        }
Beispiel #6
0
        /// <summary>
        /// Starts the inventory manager.
        /// </summary>
        public static void StartInventoryManager()
        {
            int choice = 0;

            while (true)
            {
                Console.WriteLine("1.Rice");
                Console.WriteLine("2.Wheat");
                Console.WriteLine("3.Pulses");
                Console.WriteLine("\nSelect an Inventory : ");
                string stringchoice = Console.ReadLine();

                ////validate number
                if (InventoryMngtUtility.IsNumber(stringchoice) == false)
                {
                    Console.WriteLine("\nInvalid Input");
                    continue;
                }

                ////Convert to integer
                choice = Convert.ToInt32(stringchoice);

                ////Calls the metods base on the Choosen choice.
                switch (choice)
                {
                case 1:
                    InventoryMenu.InventoryMenuview("RICE");
                    break;

                case 2:
                    InventoryMenu.InventoryMenuview("WHEAT");
                    break;

                case 3:
                    InventoryMenu.InventoryMenuview("PULSES");
                    break;

                default:
                    return;
                }
            }
        }
Beispiel #7
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");
        }
Beispiel #8
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);
            }
        }
Beispiel #9
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");
            }
        }
Beispiel #10
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");
            }
        }