Пример #1
0
        private static List <Order> UsersListOfOrders()
        {
            bool ordering = true;

            var configBuilder = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            IConfigurationRoot configuration = configBuilder.Build();

            var optionsBuilder = new DbContextOptionsBuilder <ContextPizza.pizzadatabaseContext>(); //DbContext?

            optionsBuilder.UseSqlServer(configuration.GetConnectionString("pizzadatabase"));
            var options    = optionsBuilder.Options;
            var dbContext  = new ContextPizza.pizzadatabaseContext(options);
            var repository = new pizzalibrary.pizzarepository(dbContext);

            while (ordering)
            {
                Console.WriteLine("\nPlease enter a username and user lastname for this new pizza.");
                string   user       = Console.ReadLine();
                string[] userinfo   = user.Split();
                bool     createUser = false;

                if (!MasterOrderList.SearchUser(masterList, userinfo))
                {
                    Console.Write("Would you like to add it? y/n\n");
                    string userCreateAnswer = Console.ReadLine();

                    switch (userCreateAnswer)
                    {
                    case "y":
                        Console.WriteLine("\nLogged in as " + userinfo[0] + ".");
                        createUser = true;
                        break;

                    case "n":
                        Console.WriteLine("\nUsername required to complete order.");
                        UsersListOfOrders();
                        break;

                    default:
                        Console.WriteLine("\nError: unknown input. Restarting order process.");
                        UsersListOfOrders();
                        break;
                    }
                }

                else if (userinfo.Length < 2)
                {
                    Console.WriteLine("\nInvalid format.");
                    UsersListOfOrders();
                }


                bool          chooseLocation = true;
                string        location       = "";
                StoreLocation s = new StoreLocation();

                while (chooseLocation)
                {
                    Console.WriteLine("\nPlease enter a location for which this pizza may be ordered.");
                    location = Console.ReadLine();

                    if (!MasterOrderList.SearchLocation(masterList, location))
                    {
                        Console.Write("\nSorry. Invalid location. Please try again.");
                    }

                    else if (s.CheckIfEmptyInventory(s))
                    {
                        Console.Write("\nThat location has an empty ingredient! Please order later.");
                    }

                    else
                    {
                        Console.WriteLine("\n" + location + " has been confirmed.");
                        s.Location = location;
                        User u = new User(userinfo[0], userinfo[1], location, DateTime.Today);
                        if (!createUser)
                        {
                            repository.Useradd(u);
                            repository.Save();
                        }

                        chooseLocation = false;
                    }
                }

                return(MakePizzas(currentListOfUserOrders, s, new User(userinfo[0], userinfo[1], location, DateTime.Now)));
            }

            return(currentListOfUserOrders);
        }
Пример #2
0
        private static List <Order> UsersListOfOrders()
        {
            bool ordering = true;

            while (ordering)
            {
                Console.WriteLine("\nPlease enter a username and user lastname for this new pizza.");
                string   user     = Console.ReadLine();
                string[] userinfo = user.Split();

                if (!MasterOrderList.SearchUser(masterList, userinfo))
                {
                    Console.Write("Would you like to add it? y/n\n");
                    string userCreateAnswer = Console.ReadLine();

                    switch (userCreateAnswer)
                    {
                    case "y":
                        Console.WriteLine("\nLogged in as " + userinfo[0] + ".");
                        break;

                    case "n":
                        Console.WriteLine("\nUsername required to complete order.");
                        UsersListOfOrders();
                        break;

                    default:
                        Console.WriteLine("\nError: unknown input. Restarting order process.");
                        UsersListOfOrders();
                        break;
                    }
                }

                else if (userinfo.Length < 2)
                {
                    Console.WriteLine("\nInvalid format.");
                    UsersListOfOrders();
                }

                bool          chooseLocation = true;
                string        location       = "";
                StoreLocation s = new StoreLocation();

                while (chooseLocation)
                {
                    Console.WriteLine("\nPlease enter a location for which this pizza may be ordered.");
                    location = Console.ReadLine();

                    if (!MasterOrderList.SearchLocation(masterList, location))
                    {
                        Console.Write("\nSorry. Invalid location. Please try again.");
                    }

                    else if (s.CheckIfEmptyInventory(s))
                    {
                        Console.Write("\nThat location has an empty ingredient! Please order later.");
                    }

                    else
                    {
                        Console.WriteLine("\n" + location + " has been confirmed.");
                        s.Location     = location;
                        chooseLocation = false;
                    }
                }

                return(MakePizzas(currentListOfUserOrders, s, new User(userinfo[0], userinfo[1], location, DateTime.Now)));
            }

            return(currentListOfUserOrders);
        }