protected void ShowItems() { Console.Clear(); Console.WriteLine("ID \tName \t Amount \t Value"); foreach (var item in ShopDBProvider.GetInstance().GetItemsList()) { Console.WriteLine("{0}. {1}\t{2}\t{3}", item.ID, item.Name, item.Amount, item.Value); } Console.WriteLine("Press enter"); Console.ReadLine(); }
protected void ChangeItemValue() { Console.WriteLine("Select item"); if (!int.TryParse(Console.ReadLine(), out int itemID)) { throw new Exception("incorrect value"); } Console.WriteLine("Input item value"); if (!double.TryParse(Console.ReadLine(), out double itemValue)) { throw new Exception("incorrect value"); } ShopDBProvider.GetInstance().ChangePrice(itemID, itemValue); }
protected void Sell() { ShowItems(); Console.WriteLine("Select item ID to sell"); if (!int.TryParse(Console.ReadLine(), out int itemID)) { throw new Exception("incorrect value"); } Console.WriteLine("Select amount to sell"); if (!int.TryParse(Console.ReadLine(), out int itemAmount)) { throw new Exception("incorrect value"); } ShopDBProvider.GetInstance().SellItem(itemID, itemAmount); }
protected void AddItem() { ShowItems(); Console.WriteLine("Input item name"); string itemName = Console.ReadLine(); Console.WriteLine("input item price"); if (!int.TryParse(Console.ReadLine(), out int itemAmount)) { throw new Exception("incorrect value"); } if (!double.TryParse(Console.ReadLine(), out double itemPrice)) { throw new Exception("incorrect value"); } ShopDBProvider.GetInstance().AddItem(itemName, itemAmount, itemPrice); }