Exemplo n.º 1
0
        /// <summary>
        /// Lets the user input the customer id - guid - to fetch the relevant address information. Includes a TryCatch and the method CustomerMethods.DisplayCustomers()
        /// </summary>
        public static void DisplayCombined()
        {
            using (var context = new OnlineShopDbContext())
            {
                CustomerMethods.DisplayCustomers();


                while (true)
                {
                    Console.WriteLine("\nEnter the GUID that belongs to the customer you want the address to: \n");
                    try
                    {
                        var customerId = Guid.Parse(Console.ReadLine());
                        Console.Clear();
                        var customer = context.Customers.Find(customerId);

                        var address = context.Addresses.Find(customer.AddressID);

                        if (customer != null)
                        {
                            Console.Clear();
                            Console.WriteLine("\nThe customer you have selected is:\n" +
                                              $"{customer.FirstName} {customer.LastName}\n" +
                                              $"\nand their home address is\n" +
                                              $"\n{address.StreetName}\n{address.PostalCode} {address.City}\n");

                            Console.WriteLine("\n----------------------------------------\n");



                            Console.WriteLine("\nWhat would you like to do next?\n" +
                                              "\n1. Choose another customer" +
                                              "\n2. Go back to the main menu\n");

                            var choice = Console.ReadLine();
                            Console.Clear();
                            if (choice == "2")
                            {
                                Program.MainMenuStart();
                            }
                        }
                        else
                        {
                            Console.Clear();
                            Console.WriteLine($"\n{customerId} is not recognized. Try again!\n");
                            Console.WriteLine("\n----------------------------------------\n");
                        }
                    }
                    catch (Exception)
                    {
                        Console.Clear();
                        Console.WriteLine("\nSomething went wrong. Try again!\n");
                        Console.WriteLine("\n----------------------------------------\n");
                        CustomerMethods.DisplayCustomers();
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Main menu. Includes a TryCatch in case of wrong input.
        /// Also include references to the following methods
        /// newSeed.Seed(),
        /// AddressMethods.MainMenuAddresses(),
        /// CustomerMethods.MainMenuCustomers(),
        /// CombineMethods.DisplayCombined(),
        /// </summary>
        public static void MainMenuStart()
        {
            Console.WriteLine("\nWhat would you like look at?\n");
            Console.WriteLine("0. Seed");
            Console.WriteLine("1. Addresses ");
            Console.WriteLine("2. Customers");
            Console.WriteLine("3. Customer and address");
            Console.WriteLine("4. Exit console app\n");

            try
            {
                var choice = Console.ReadLine();
                Console.Clear();

                if (choice == "0")
                {
                    var newSeed = new Seeds();
                    newSeed.Seed();
                }

                else if (choice == "1")
                {
                    AddressMethods.MainMenuAddresses();
                }

                else if (choice == "2")
                {
                    CustomerMethods.MainMenuCustomers();
                }

                else if (choice == "3")
                {
                    CombineMethods.DisplayCombined();
                }
                else if (choice == "4")
                {
                    Environment.Exit(0);
                }
                else
                {
                    Console.WriteLine($"{choice} is not recognized. Try again!");

                    MainMenuStart();
                }
            }
            catch (Exception)
            {
                Console.WriteLine("\nSomething went wrong. Try again!\n");
                Console.WriteLine("\n----------------------------------------\n");
                MainMenuStart();
            } // In case the input is not a string this will prevent the app from shutting down
        }