Exemple #1
0
 public async Task ManageAddresses()
 {
     Console.WriteLine("What do you want to do?\n1 - Show existing addresses\n2 - Add address\n3 - Remove addresses");
     while (true)
     {
         Int32.TryParse(Console.ReadLine(), out int managerChoice);
         if (managerChoice < 1 || managerChoice > 3)
         {
             Console.WriteLine("Invalid selection. Try again");
         }
         else
         {
             ManageAddresses addreses = new ManageAddresses();
             if (managerChoice == 1)
             {
                 await addreses.ShowAddresses();
             }
             else if (managerChoice == 2)
             {
                 await addreses.AddAddress();
             }
             else if (managerChoice == 3)
             {
                 await addreses.RemoveAddress();
             }
         }
     }
 }
Exemple #2
0
 public async Task AddShop()
 {
     using (var context = new ShopContext())
     {
         Shop            shop      = new Shop();
         ManageAddresses addresses = new ManageAddresses();
         Console.WriteLine("Please, select the name for the shop.");
         shop.ShopName = Console.ReadLine();
         Console.WriteLine("Please, select the address for the shop by index.");
         addresses.ListOfAddresses();
         while (true)
         {
             Int32.TryParse(Console.ReadLine(), out int selectedIndex);
             if ((context.Addresses.Count() <= (selectedIndex - 1)) && ((selectedIndex - 1) >= 0))
             {
                 shop.Address = context.Addresses.ElementAt(selectedIndex - 1);
                 context.SaveChanges();
                 break;
             }
             else
             {
                 Console.WriteLine("Invalid selection. Try again.");
             }
         }
         context.SaveChanges();
         Console.WriteLine("The shop is added. Do you want to add other shops? (Y/N)");
         while (true)
         {
             string answer = Console.ReadLine();
             if (answer.ToLower() == "y")
             {
                 await AddShop(); break;
             }
             else if (answer.ToLower() == "n")
             {
                 await Management.ManageShops(); break;
             }
             else
             {
                 Console.WriteLine("Invalid input. Try again.");
             }
         }
     }
 }