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);
        }
        public static void OrderDetails(IProject0Repo p0Repo)
        {
            ILogger logger = LogManager.GetCurrentClassLogger();

            Console.WriteLine("Please enter an order Id:");
            var input = Console.ReadLine();

            if (int.TryParse(input, out var orderId))
            {
                if (!p0Repo.CheckOrderExists(orderId))
                {
                    logger.Error("That order is not in the system.");
                }
                else
                {
                    ConsoleDisplay.DisplayOrder(p0Repo.GetCupcakeOrder(orderId),
                                                p0Repo.GetOrderItems(orderId).ToList(),
                                                p0Repo.GetAllCupcakes().ToList());
                }
            }
            else
            {
                logger.Error($"Invalid input {input}");
            }
        }
        public static Dictionary <int, int> GetCupcakes(IProject0Repo p0Repo)
        {
            ILogger logger = LogManager.GetCurrentClassLogger();

            List <Library.Cupcake> cupcakes = p0Repo.GetAllCupcakes().ToList();
            string input;
            Dictionary <int, int> cupcakeInputs = new Dictionary <int, int>();

            while (true)
            {
                ConsoleDisplay.CupcakeList(cupcakes);
                Console.WriteLine("Please enter the number of a cupcake that you would like to order\n" +
                                  "or 'C' to continue:");

                GetMenuInput(out input);

                if (input == "C")
                {
                    break;
                }
                else
                {
                    if (int.TryParse(input, out var cupcakeId))
                    {
                        if (!p0Repo.CheckCupcakeExists(cupcakeId))
                        {
                            logger.Error($"{cupcakeId} is not in the list of cupcakes.");
                            cupcakeInputs.Clear();
                            return(cupcakeInputs);
                        }
                        if (cupcakeInputs.ContainsKey(cupcakeId))
                        {
                            logger.Error("You have already selected that cupcake in this order.");
                            Console.WriteLine();
                        }
                        else
                        {
                            cupcakeInputs[cupcakeId] = GetCupcakeQuantity();
                            if (cupcakeInputs[cupcakeId] == -1)
                            {
                                cupcakeInputs.Clear();
                                return(cupcakeInputs);
                            }
                            // Remove cupcake from the temporary list of cupcakes
                            // to deter the user from re-entering it. If they re-enter it anyway
                            // they will get an error.
                            cupcakes.Remove(cupcakes.Single(c => c.Id == cupcakeId));
                        }
                    }
                    else
                    {
                        logger.Error($"Invalid input {input}");
                        cupcakeInputs.Clear();
                        return(cupcakeInputs);
                    }
                }
            }
            return(cupcakeInputs);
        }
        public static void CustomerSearch(IProject0Repo p0Repo)
        {
            ILogger logger = LogManager.GetCurrentClassLogger();

            string fName = GetCustomerFirstName();

            if (fName is null)
            {
                return;
            }

            List <Library.Customer> customers = p0Repo.GetAllCustomers().ToList();

            // Try to find a match to the first name
            var numPossibleMatches = customers.Count(c => c.FirstName == fName);

            if (numPossibleMatches > 0)
            {
                Console.WriteLine($"Found {numPossibleMatches} with that first name.");
                var possibleMatches = customers.Where(c => c.FirstName == fName);
                List <Library.Customer> customerList = new List <Library.Customer>();
                foreach (var item in possibleMatches)
                {
                    customerList.Add(item);
                }

                string lName = GetCustomerLastName();
                if (lName is null)
                {
                    return;
                }
                // Try to find a match to the last name
                numPossibleMatches = customerList.Count(c => c.LastName == lName);
                if (numPossibleMatches > 0)
                {
                    possibleMatches = customerList.Where(c => c.LastName == lName);
                    Console.WriteLine();
                    Console.WriteLine("List of customer's with that first name and last name:");
                    Console.WriteLine();
                    foreach (var item in possibleMatches)
                    {
                        Console.WriteLine($"Customer Id: {item.Id}, First Name: {item.FirstName}, " +
                                          $"Last Name, {item.LastName}, Default Location Id: {item.DefaultLocation}");
                    }
                }
                else
                {
                    logger.Error("There is no one in the system with that first name and last name.");
                }
            }
            else
            {
                logger.Error("There is no one in the system with that first name.");
            }
        }
示例#5
0
        public static void GetDataAndAddLocation(IProject0Repo p0Repo)
        {
            // Add location requires no user input. It adds a store with an Id that is one more
            // than the last Id using the database.
            p0Repo.AddLocation();
            // Get the Id of the last store that was added, and report that to the user.
            int newLocationId = p0Repo.GetLastLocationAdded();

            p0Repo.FillLocationInventory(newLocationId);
            Console.WriteLine($"Location with Id of {newLocationId} successfully created!");
        }
        public static void OrderList(IProject0Repo p0Repo, List <Library.Order> orders,
                                     List <Library.OrderItem> orderItems, List <Library.Cupcake> cupcakes, List <Library.Location> locations)
        {
            Console.WriteLine("Please select from the following filters ('N' for no filter)");
            Console.WriteLine("'E': Earliest orders first");
            Console.WriteLine("'L': Latest orders first");
            Console.WriteLine("'C': Cheapest orders first");
            Console.WriteLine("'X': Most expensive orders first");
            Console.WriteLine();
            Console.WriteLine("Please type a selection to see a list of orders: ");
            ConsoleRead.GetMenuInput(out var input);
            List <Library.Order> modOrders = new List <Library.Order>();

            if (input == "E")
            {
                foreach (var item in orders.OrderBy(o => o.OrderTime))
                {
                    modOrders.Add(item);
                }
                DisplayOrders(p0Repo, modOrders, orderItems, cupcakes, locations, "List of Orders (earliest to latest):");
            }
            else if (input == "L")
            {
                foreach (var item in orders.OrderByDescending(o => o.OrderTime))
                {
                    modOrders.Add(item);
                }
                DisplayOrders(p0Repo, modOrders, orderItems, cupcakes, locations, "List of Orders (latest to earliest):");
            }
            else if (input == "C")
            {
                foreach (var item in orders.OrderBy(o =>
                                                    o.GetTotalCost(p0Repo.GetOrderItems(o.Id).ToList(), cupcakes)))
                {
                    modOrders.Add(item);
                }
                DisplayOrders(p0Repo, modOrders, orderItems, cupcakes, locations,
                              "List of Orders (cheapest to most expensive):");
            }
            else if (input == "X")
            {
                foreach (var item in orders.OrderByDescending(o =>
                                                              o.GetTotalCost(p0Repo.GetOrderItems(o.Id).ToList(), cupcakes)))
                {
                    modOrders.Add(item);
                }
                DisplayOrders(p0Repo, modOrders, orderItems, cupcakes, locations,
                              "List of Orders (most expensive to cheapest):");
            }
            else
            {
                DisplayOrders(p0Repo, orders, orderItems, cupcakes, locations, "List of Orders:");
            }
        }
        public static void LocationList(IProject0Repo p0Repo)
        {
            Console.WriteLine("List of Available Store Locations:");
            Console.WriteLine();
            var locations = p0Repo.GetAllLocations().ToList();

            foreach (var item in locations)
            {
                Console.WriteLine($"Location Id: {item.Id}");
            }
        }
        public static void CustomerList(IProject0Repo p0Repo)
        {
            Console.WriteLine("List of Customers:");
            Console.WriteLine();
            var customers = p0Repo.GetAllCustomers().ToList();

            foreach (var item in customers)
            {
                Console.WriteLine($"Customer Id: {item.Id}, First Name: {item.FirstName}, " +
                                  $"Last Name, {item.LastName}, Default Location Id: {item.DefaultLocation}");
            }
        }
        public static void OrderRecommended(IProject0Repo p0Repo)
        {
            ILogger logger = LogManager.GetCurrentClassLogger();

            int customerId = GetCustomer(p0Repo);

            if (!p0Repo.CheckCustomerExists(customerId))
            {
                return;
            }

            var customer   = p0Repo.GetAllCustomers().ToList().Single(c => c.Id == customerId);
            var orderItems = p0Repo.GetAllOrderItems().ToList();
            var cupcakes   = p0Repo.GetAllCupcakes().ToList();

            var customerOrderItems = p0Repo.GetCustomerOrderItems(customerId).ToList();

            if (customerOrderItems.Count() > 0)
            {
                // https://stackoverflow.com/questions/6730974/select-most-frequent-value-using-linq
                // Get the most frequent order, if there is a tie, then lowest Id wins
                var mostFrequentOrder = customerOrderItems.OrderBy(o => o.CupcakeId)
                                        .GroupBy(o => o.CupcakeId)
                                        .OrderByDescending(gp => gp.Count())
                                        .Take(1);
                // https://code.i-harness.com/en/q/820541
                var    intermediate     = mostFrequentOrder.First();
                string orderRecommended = "not assigned";
                foreach (var item in intermediate)
                {
                    orderRecommended = cupcakes.Single(c => c.Id == item.CupcakeId).Type;
                    break;
                }

                if (orderRecommended == "not assigned")
                {
                    logger.Error($"Unable to find recommended order for customer {customer.FirstName}" +
                                 $" {customer.LastName}");
                }
                else
                {
                    Console.WriteLine($"Order recommended count: {mostFrequentOrder.Count()}");
                    Console.WriteLine($"Recommended Order for Customer {customer.FirstName}" +
                                      $" {customer.LastName}: {orderRecommended}");
                }
            }
            else
            {
                logger.Error($"Unable to find recommended order for customer {customer.FirstName}" +
                             $" {customer.LastName}");
            }
        }
示例#10
0
        public static void GetDataAndAddCustomer(IProject0Repo p0Repo)
        {
            NLog.ILogger logger = LogManager.GetCurrentClassLogger();

            // Get all locations in order to validate if a customer can be added.
            // A location must exist in order for a customer to be added.
            var locations = p0Repo.GetAllLocations().ToList();

            if (locations.Count <= 0)
            {
                logger.Error("You must add at least one store location before you can add a customer.");
                return;
            }

            // Get a first name
            string fName = ConsoleRead.GetCustomerFirstName();

            if (fName is null)
            {
                return;
            }
            // Get a last name
            string lName = ConsoleRead.GetCustomerLastName();

            if (lName is null)
            {
                return;
            }
            Console.WriteLine();

            // Get a location for customer's default location
            int locationId = ConsoleRead.GetLocation(p0Repo,
                                                     "Please enter a valid Id for default store location:", -1);

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

            // Add the customer
            p0Repo.AddCustomer(fName, lName, locationId);
            // Get the Id of the customer that was just added and report that to the user
            int newCustomerId = p0Repo.GetLastCustomerAdded();

            Console.WriteLine($"Customer with Id of {newCustomerId} successfully created!");
        }
        public static void DisplayOrders(IProject0Repo p0Repo, List <Library.Order> orders,
                                         List <Library.OrderItem> orderItems,
                                         List <Library.Cupcake> cupcakes, List <Library.Location> locations, string prompt)
        {
            Console.WriteLine(prompt);
            Console.WriteLine();
            decimal sum         = 0;
            decimal avg         = 0;
            int     incrementer = 1;

            foreach (var item in orders)
            {
                Console.WriteLine($"Order Id: {item.Id}, Location Id: {item.OrderLocation}, " +
                                  $"Customer Id, {item.OrderCustomer}, Order Time: {item.OrderTime},");
                List <Library.OrderItem> thisOrderItems = p0Repo.GetOrderItems(item.Id).ToList();
                foreach (var orderItem in thisOrderItems)
                {
                    Console.WriteLine($"\tOrder Item {incrementer}: " +
                                      $"{cupcakes.Single(c => c.Id == orderItem.CupcakeId).Type}, \n" +
                                      $"\tQnty {incrementer}: {orderItem.Quantity}");
                    incrementer++;
                    // Add to the sum for order total and order average
                    sum += orderItem.Quantity * cupcakes.Single(c => c.Id == orderItem.CupcakeId).Cost;
                }

                Console.WriteLine($"Order Id {item.Id} total cost: ${sum}");
                avg        += sum;
                sum         = 0;
                incrementer = 1;
                Console.WriteLine();
            }
            if (orders.Count() > 0)
            {
                avg /= orders.Count();
                // https://stackoverflow.com/questions/1291483/leave-only-two-decimal-places-after-the-dot
                // This takes the decimal average and stringifys it to two decimal places
                string avgString = String.Format("{0:0.00}", avg);
                Console.WriteLine("Other order statistics...");
                Console.WriteLine($"Average Order Total: " +
                                  $"${avgString}");
                Console.WriteLine($"Order with the latest date: " +
                                  $"{orders.Max(o => o.OrderTime)}");
                if (!(locations is null))
                {
                    var storeWithMostOrders = locations.MaxBy(sL =>
                                                              p0Repo.GetLocationOrderHistory(sL.Id).Count()).OrderBy(sL => sL.Id).First();
                    Console.WriteLine($"Store Id with the most orders: {storeWithMostOrders.Id}");
                }
            }
        }
        public static int GetCustomer(IProject0Repo p0Repo)
        {
            ILogger logger = LogManager.GetCurrentClassLogger();

            ConsoleDisplay.CustomerList(p0Repo);
            Console.WriteLine();
            Console.WriteLine("Please enter a valid customer Id for the order:");
            var input = Console.ReadLine();

            if (int.TryParse(input, out var customerId))
            {
                return(customerId);
            }
            else
            {
                logger.Error($"Invalid input {input}");
                return(-1);
            }
        }
        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}");
            }
        }
        public static int GetLocation(IProject0Repo p0Repo, string prompt, int customerId)
        {
            ILogger logger = LogManager.GetCurrentClassLogger();

            ConsoleDisplay.LocationList(p0Repo);
            Console.WriteLine();
            Console.WriteLine(prompt);
            var input = Console.ReadLine();

            if (input == "d" && customerId != -1)
            {
                return(p0Repo.GetDefaultLocation(customerId));
            }
            else if (int.TryParse(input, out var locationId))
            {
                return(locationId);
            }
            else
            {
                logger.Error($"Invalid input {input}");
                return(-1);
            }
        }
示例#15
0
 public OrderController(IProject0Repo <OrderHistory> newRepo)
 {
     this.repository = newRepo;
 }
示例#16
0
 public OrderController()
 {
     repository = new GenericRepository <OrderHistory>();
 }
示例#17
0
        /// <summary>
        /// repo constructors
        /// </summary>
        ///

        //initizalize the controller
        public CustomerController()
        {
            repository = new GenericRepository <da.Customer>();
        }
示例#18
0
        public static void GetDataAndAddOrder(IProject0Repo p0Repo)
        {
            NLog.ILogger logger = LogManager.GetCurrentClassLogger();

            // Get all customers to validate that there is at least one customer.
            // There must be at least one customer to place an order.
            List <Library.Customer> customers = p0Repo.GetAllCustomers().ToList();

            if (customers.Count == 0)
            {
                logger.Error("You have to add at least one customer before you can add an order.");
                return;
            }
            // Get a customer
            int customerId = ConsoleRead.GetCustomer(p0Repo);

            if (customerId == -1)
            {
                return;
            }
            if (!p0Repo.CheckCustomerExists(customerId))
            {
                logger.Error($"Customer {customerId} is not in the list of customers.");
                return;
            }
            // Get a location
            int locationId = ConsoleRead.GetLocation(p0Repo,
                                                     "Please enter a valid store Id for the order or 'd' for customer default location:", customerId);

            if (locationId == -1)
            {
                return;
            }
            if (!p0Repo.CheckLocationExists(locationId))
            {
                logger.Error($"Location {locationId} is not in the list of stores.");
                return;
            }
            // The following checks to see if the customer can order from this store location
            // If the customer has ordered at this store within the past 2 hours, than they shouldn't be
            // able to order again.
            var orders = p0Repo.GetAllOrders().ToList();

            if (Library.Customer.CheckCustomerCannotOrder(customerId, locationId, orders))
            {
                logger.Error("Customer can't place an order at this store because it hasn't been 2 hours \n" +
                             "since there last order yet.");
                return;
            }
            // Get some cupcakes from the user inputs, both type and quantity
            // These are placed in a dictionary.
            Dictionary <int, int> cupcakeInputs = ConsoleRead.GetCupcakes(p0Repo);

            if (cupcakeInputs.Count == 0)
            {
                return;
            }
            bool cupcakeFound = false;

            foreach (var item in cupcakeInputs)
            {
                if (item.Value > 0)
                {
                    cupcakeFound = true;
                    break;
                }
            }
            // Make sure that the user entered at least one cupcake, qnty pairing
            // No empty orders, no orders with zero quantities.
            if (!cupcakeFound)
            {
                logger.Error("You must enter at least one cupcake to place an order.");
                return;
            }
            // The following gets all orders and their associated order items in order
            // to validate that the store location's supply of the cupcakes in the customer's
            // requested order have not been exhausted.
            // Cupcake exhaustion happens when a store location has had more than 1000 cupcakes of one
            // type sold within 24 hours, at that point they cannot sell anymore.
            // This is arbitrary business logic that I added in order to satisfy the Project0
            // requirements.
            var orderItems = p0Repo.GetAllOrderItems().ToList();

            if (!Library.Location.CheckCanOrderCupcake(locationId, cupcakeInputs, orders, orderItems))
            {
                logger.Error("This store has exhausted supply of that cupcake. Try back in 24 hours.");
                return;
            }
            // The following gets the recipes for the cupcakes in the customer's requested order
            // and checks to make sure that the store location's inventory can support the order.
            var recipes     = p0Repo.GetRecipes(cupcakeInputs);
            var locationInv = p0Repo.GetLocationInv(locationId);

            if (!Library.Location.CheckOrderFeasible(recipes, locationInv, cupcakeInputs))
            {
                logger.Error("This store does not have enough ingredients to place the requested order.");
                return;
            }

            // Add the cupcake order
            p0Repo.AddCupcakeOrder(locationId, customerId);
            // Get the new order Id that was just added in order to report it to the user.
            int newOrderId = p0Repo.GetLastCupcakeOrderAdded();

            // Add the order items to the cupcake order
            p0Repo.AddCupcakeOrderItems(newOrderId, cupcakeInputs);
            // Remove ingredient quantities from the store location's inventory
            p0Repo.UpdateLocationInv(locationId, recipes, cupcakeInputs);
            Console.WriteLine($"Order with Id of {newOrderId} successfully created!");
        }
示例#19
0
 // intialiize the locationcontroller repo,
 public LocationController()
 {
     repository = new GenericRepository <Models.Location>();
 }
示例#20
0
 public LocationController(IProject0Repo <Models.Location> newRepo)
 {
     repository = newRepo;
 }
示例#21
0
 public ProductController()
 {
     repository = new GenericRepository <Models.Product>();
 }
示例#22
0
 public ProductController(IProject0Repo <Models.Product> newRepo)
 {
     repository = newRepo;
 }
示例#23
0
 public CustomerController(IProject0Repo <da.Customer> newRepo)
 {
     this.repository = newRepo;
 }