Ejemplo n.º 1
0
        public static void LocationOrders(IProject0Repo p0Repo)
        {
            ILogger logger = LogManager.GetCurrentClassLogger();

            // Get location
            int locationId = GetLocation(p0Repo,
                                         "Please enter the store location Id to get that location's orders:", -1);

            if (locationId == -1)
            {
                return;
            }
            if (!p0Repo.CheckLocationExists(locationId))
            {
                logger.Error("This location is not in the system.");
                return;
            }

            // Get all cupcakes
            var cupcakes = p0Repo.GetAllCupcakes().ToList();
            // Get specific location orders
            var locationOrderHistory = p0Repo.GetLocationOrderHistory(locationId).ToList();
            // Get all order items
            var orderItems = p0Repo.GetAllOrderItems().ToList();

            Console.WriteLine($"Store Location {locationId}");
            Console.WriteLine();
            // Send all information to OrderList to display the orders
            ConsoleDisplay.OrderList(p0Repo, locationOrderHistory, orderItems, cupcakes, null);
        }
Ejemplo n.º 2
0
        public static void CustomerOrders(IProject0Repo p0Repo)
        {
            ILogger logger = LogManager.GetCurrentClassLogger();

            // Get all customers
            var customers = p0Repo.GetAllCustomers().ToList();

            ConsoleDisplay.CustomerList(p0Repo);
            Console.WriteLine();
            Console.WriteLine("Please enter the customer Id to get that customer's orders:");
            var input = Console.ReadLine();

            if (int.TryParse(input, out var customerId))
            {
                if (!p0Repo.CheckCustomerExists(customerId))
                {
                    logger.Error($"Customer {customerId} is not in the list of customers.");
                    return;
                }
                foreach (var item in customers.Where(c => c.Id == customerId))
                {
                    Console.WriteLine($"Customer {item.FirstName} {item.LastName}");
                    Console.WriteLine();
                    // Get specific customer's orders
                    var customerOrderHistory = p0Repo.GetCustomerOrderHistory(customerId).ToList();
                    // Get all cupcakes
                    var cupcakes = p0Repo.GetAllCupcakes().ToList();
                    // Get all order items
                    var orderItems = p0Repo.GetAllOrderItems().ToList();
                    // Send information to OrderList to be displayed
                    ConsoleDisplay.OrderList(p0Repo, customerOrderHistory, orderItems, cupcakes, null);
                }
            }
            else
            {
                logger.Error($"Invalid input {input}");
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            ILogger logger = LogManager.GetCurrentClassLogger();

            string jsonLocations = @"C:\revature\luigi_cupcakes_locations.json";
            string jsonCustomers = @"C:\revature\luigi_cupcakes_customers.json";
            string jsonOrders    = @"C:\revature\luigi_cupcakes_orders.json";

            LoadDataFromJSON(jsonLocations,
                             jsonCustomers,
                             jsonOrders,
                             out var storeLocations,
                             out var customers,
                             out var orders);

            Console.WriteLine("Welcome to Luigi's Cupcakes Manager");
            Console.WriteLine();
            Console.WriteLine("Please select from the following options (not case-sensitive):");

            while (true)
            {
                ConsoleDisplay.DisplayMenu();
                ConsoleRead.GetMenuInput(out var input);
                if (input == "S")
                {
                    GetDataAndAddLocation(jsonLocations, storeLocations);
                }
                else if (input == "C")
                {
                    GetDataAndAddCustomer(jsonCustomers, customers, storeLocations);
                }
                else if (input == "O")
                {
                    GetDataAndAddOrder(jsonLocations, jsonCustomers, jsonOrders,
                                       customers, storeLocations, orders);
                }
                else if (input == "SL")
                {
                    ConsoleDisplay.StoreList(storeLocations);
                }
                else if (input == "SO")
                {
                    ConsoleRead.StoreOrders(storeLocations);
                }
                else if (input == "CL")
                {
                    ConsoleDisplay.CustomerList(customers);
                }
                else if (input == "CS")
                {
                    ConsoleRead.CustomerSearch(customers);
                }
                else if (input == "CO")
                {
                    ConsoleRead.CustomerOrders(customers);
                }
                else if (input == "OL")
                {
                    ConsoleDisplay.OrderList(orders, storeLocations);
                }
                else if (input == "OR")
                {
                    ConsoleRead.OrderRecommended(customers, orders);
                }
                else if (input == "Q")
                {
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        /// <remarks>
        ///  The following command is the command in Package Manager Console to scaffold and re-scaffold the
        ///  database. I have had to do this 4-5 times already, so I have the command at the top of the
        ///  program so I can grab it.
        /// </remarks>
        // Scaffold-DbContext "<your-connection-string>"
        //      Microsoft.EntityFrameworkCore.SqlServer
        //      -Project <name-of-data-project>

        /// <remarks>
        ///  The following line of code is commented out so that the SQL logging does not interfere with
        ///  using the console. Once the console UI is replaced with a website, I plan on turning
        ///  the SQL logging to the console back on since there will no longer be a conflict.
        /// </remarks>
        /// <param name="args"></param>
        //public static readonly LoggerFactory AppLoggerFactory
        //    = new LoggerFactory(new[] { new ConsoleLoggerProvider((_, __) => true, true) });

        static void Main(string[] args)
        {
            NLog.ILogger logger = LogManager.GetCurrentClassLogger();

            var optionsBuilder = new DbContextOptionsBuilder <Project0Context>();

            optionsBuilder.UseSqlServer(SecretConfiguration.ConnectionString);
            //optionsBuilder.UseLoggerFactory(AppLoggerFactory);
            var options = optionsBuilder.Options;

            using (var dbContext = new Project0Context(options))
            {
                IProject0Repo p0Repo = new Project0Repo(dbContext);

                Console.WriteLine("Welcome to Matt's Cupcakes Manager");
                Console.WriteLine();
                Console.WriteLine("Please select from the following options (not case-sensitive):");

                while (true)
                {
                    ConsoleDisplay.DisplayMenu();
                    ConsoleRead.GetMenuInput(out var input);
                    if (input == "L")
                    {
                        GetDataAndAddLocation(p0Repo);
                    }
                    else if (input == "C")
                    {
                        GetDataAndAddCustomer(p0Repo);
                    }
                    else if (input == "O")
                    {
                        GetDataAndAddOrder(p0Repo);
                    }
                    else if (input == "LL")
                    {
                        ConsoleDisplay.LocationList(p0Repo);
                    }
                    else if (input == "LO")
                    {
                        ConsoleRead.LocationOrders(p0Repo);
                    }
                    else if (input == "CL")
                    {
                        ConsoleDisplay.CustomerList(p0Repo);
                    }
                    else if (input == "CS")
                    {
                        ConsoleRead.CustomerSearch(p0Repo);
                    }
                    else if (input == "CO")
                    {
                        ConsoleRead.CustomerOrders(p0Repo);
                    }
                    else if (input == "OD")
                    {
                        ConsoleRead.OrderDetails(p0Repo);
                    }
                    else if (input == "OL")
                    {
                        ConsoleDisplay.OrderList(p0Repo, p0Repo.GetAllOrders().ToList(),
                                                 p0Repo.GetAllOrderItems().ToList(),
                                                 p0Repo.GetAllCupcakes().ToList(), p0Repo.GetAllLocations().ToList());
                    }
                    else if (input == "OR")
                    {
                        ConsoleRead.OrderRecommended(p0Repo);
                    }
                    else if (input == "Q")
                    {
                        break;
                    }
                }
            }
        }