public async Task AddItem() { using (var context = new ShopContext()) { ManageShops shops = new ManageShops(); ShopItem item = new ShopItem(); Shop shop = new Shop(); Console.WriteLine("Enter brand"); item.Brand = Console.ReadLine(); Console.WriteLine("Enter price"); double.TryParse(Console.ReadLine(), out double setPrice); item.Price = setPrice; Console.WriteLine("Enter size"); int.TryParse(Console.ReadLine(), out int setSize); item.Size = setSize; Console.WriteLine("Select a shop to add an item"); shops.ListOfShops(); while (true) { Int32.TryParse(Console.ReadLine(), out int selectedIndex); if ((context.Shops.Count() <= (selectedIndex - 1)) && ((selectedIndex - 1) >= 0)) { var shopToAdd = context.Shops.Where(i => i.Id == selectedIndex).FirstOrDefault(); shopToAdd.Stock.Add(item); context.SaveChanges(); break; } else { Console.WriteLine("Invalid selection. Try again."); } } Console.WriteLine("The item is added. Do you want to add other items? (Y/N)"); while (true) { string answer = Console.ReadLine(); if (answer.ToLower() == "y") { await AddItem(); break; } else if (answer.ToLower() == "n") { await Management.ManageItems(); break; } else { Console.WriteLine("Invalid input. Try again."); } } } }
public async Task GoManaging() { Console.WriteLine("What do you want to manage?\n1 - Addresses\n2 - Shops\n3 - Sellers\n4 - Items"); while (true) { Int32.TryParse(Console.ReadLine(), out int managerChoice); if (managerChoice < 1 || managerChoice > 4) { Console.WriteLine("Invalid selection. Try again"); } else { ManagingOptions options = new ManagingOptions(); if (managerChoice == 1) { await options.ManageAddresses(); } else if (managerChoice == 2) { await options.ManageShops(); } else if (managerChoice == 3) { await options.ManageSellers(); } else if (managerChoice == 4) { await options.ManageItems(); } } } }