/// <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"); }
/// <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"); }
/// <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"); }
/// <summary> /// Does the object exist. /// </summary> /// <param name="name">The name.</param> /// <returns>returning true if object is existed</returns> public static bool DoesObjectExist(string name) { InventeryTypes inventeryTypes = InventeryFactory.ReadJsonFile(); List <RiceClass> riceList = inventeryTypes.RiceList; foreach (RiceClass riceName in riceList) { if (riceName.Name.Equals(name)) { return(true); } } return(false); }
/// <summary> /// Does the object exist. /// </summary> /// <param name="name">The name.</param> /// <returns>returning true if object is exist</returns> public static bool DoesObjectExist(string name) { InventeryTypes inventeryTypes = InventeryFactory.ReadJsonFile(); List <WheatClass> wheatList = inventeryTypes.WheatList; foreach (WheatClass wheat in wheatList) { if (wheat.Name.Equals(name)) { return(true); } } return(false); }
/// <summary> /// Does the object exist. /// </summary> /// <param name="itemName">Name of the item.</param> /// <returns>returning true if object is exist else returning false</returns> public static bool DoesObjectExist(string itemName) { InventeryTypes inventery = InventeryFactory.ReadJsonFile(); List <PulsesClass> pulseList = inventery.PulsesList; foreach (PulsesClass pulse in pulseList) { if (pulse.name.Equals(itemName)) { return(true); } } return(false); }
/// <summary> /// Gets the inventery list. /// </summary> /// <param name="inverteryType">Type of the invertery.</param> public static void GetInventeryList(string inverteryType) { InventeryTypes inventeryTypes = InventeryFactory.ReadJsonFile(); if (inventeryTypes.Equals(inverteryType)) { List <RiceClass> riceList = inventeryTypes.RiceList; foreach (RiceClass rice in riceList) { Console.WriteLine("Rice type"); Console.WriteLine("name " + rice.Name + "\tweight " + rice.Weight + "\tPricePerKg " + rice.PricePerKg); Console.WriteLine("total price of " + rice.Name + " is " + (rice.Weight * rice.PricePerKg)); Console.WriteLine("-----------------------------------------------------"); } return; } if (inventeryTypes.Equals(inverteryType)) { List <WheatClass> wheatList = inventeryTypes.WheatList; foreach (WheatClass wheat in wheatList) { Console.WriteLine("Wheat type"); Console.WriteLine("name " + wheat.Name + "\tweight" + wheat.Weight + "\tPricePerKg" + wheat.PricePerKg); Console.WriteLine("total price of " + wheat.Name + " is " + (wheat.Weight * wheat.PricePerKg)); Console.WriteLine("--------------------------------------------------"); } return; } if (inverteryType.Equals(inverteryType)) { List <PulsesClass> pulsesList = inventeryTypes.PulsesList; foreach (PulsesClass pulses in pulsesList) { Console.WriteLine("Pulses type"); Console.WriteLine("name " + pulses.Name + "\tweight " + pulses.Weight + "\tPricePerKg" + pulses.PricePerKg); Console.WriteLine("total price of " + pulses.Name + " is " + (pulses.PricePerKg * pulses.Weight)); Console.WriteLine("--------------------------------------------------------"); } return; } }
/// <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"); }
/// <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"); }
/// <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"); }
/// <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"); } } }
/// <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"); } }
/// <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"); } }