public async Task ManageShops() { Console.WriteLine("What do you want to do?\n1 - Show existing shops\n2 - Add shops\n3 - Remove shops"); while (true) { Int32.TryParse(Console.ReadLine(), out int managerChoice); if (managerChoice < 1 || managerChoice > 3) { Console.WriteLine("Invalid selection. Try again"); } else { ManageShops shops = new ManageShops(); if (managerChoice == 1) { await shops.ShowShops(); } else if (managerChoice == 2) { await shops.AddShop(); } else if (managerChoice == 3) { await shops.RemoveShop(); } } } }
public async Task WhereToGo() { Console.WriteLine($"Ok, {Customer.Name}, which shop do you want to go to?"); ManageShops shops = new ManageShops(); Order order = new Order(); shops.ListOfShops(); using (var context = new ShopContext()) { while (true) { Int32.TryParse(Console.ReadLine(), out int selectedIndex); if ((context.Shops.Count() <= (selectedIndex - 1)) && ((selectedIndex - 1) >= 0)) { var selectedShop = context.Shops.Where(i => i.Id == selectedIndex).FirstOrDefault(); foreach (var items in selectedShop.Stock) { Console.WriteLine("Ok! Here is the list of goods in this shop. Choose what to buy."); Console.WriteLine($"{items.Id} - {items.Brand}, size: {items.Size}, price {items.Price}"); } Int32.TryParse(Console.ReadLine(), out int selectedGoods); if ((selectedShop.Stock.Count() <= (selectedGoods - 1)) && ((selectedGoods - 1) >= 0)) { var orderIt = selectedShop.Stock.Where(i => i.Id == selectedGoods).FirstOrDefault(); order.Items.Add(orderIt); order.OrderDate = DateTime.Today; order.Shop = selectedShop; context.SaveChanges(); break; } } else { Console.WriteLine("Invalid selection. Try again."); } Console.WriteLine("The item is bought. Do you want to buy other items? (Y/N)"); while (true) { string answer = Console.ReadLine(); if (answer.ToLower() == "y") { await WhereToGo(); break; } else if (answer.ToLower() == "n") { await Customing.GoCustoming(); break; } else { Console.WriteLine("Invalid input. Try again."); } } } } }
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 AddSeller() { using (var context = new ShopContext()) { ManageShops shops = new ManageShops(); Seller seller = new Seller(); Console.WriteLine("Enter seller's name"); seller.Name = Console.ReadLine(); Console.WriteLine("Select a shop to add a seller"); 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(); seller.Shop = shopToAdd; context.SaveChanges(); break; } else { Console.WriteLine("Invalid selection. Try again."); } } Console.WriteLine("The seller is added. Do you want to add other sellers? (Y/N)"); while (true) { string answer = Console.ReadLine(); if (answer.ToLower() == "y") { await AddSeller(); break; } else if (answer.ToLower() == "n") { await Management.ManageSellers(); break; } else { Console.WriteLine("Invalid input. Try again."); } } } }