Beispiel #1
0
        public static void GetDataAndAddCustomer(string jsonCustomers, List <Customer> customers,
                                                 List <Location> storeLocations)
        {
            string fName = ConsoleRead.GetCustomerFirstName();

            if (fName is null)
            {
                return;
            }
            string lName = ConsoleRead.GetCustomerLastName();

            if (lName is null)
            {
                return;
            }
            bool isStores = Location.CheckForStores(storeLocations);

            if (!isStores)
            {
                Console.WriteLine("You must add at least one store before you can add a customer.");
                return;
            }
            int storeLocationId = ConsoleRead.GetStoreLocation(storeLocations,
                                                               "Please enter a valid Id for default store location:");

            if (storeLocationId == -1)
            {
                return;
            }
            bool storeExists = Location.CheckStoreExists(storeLocationId, storeLocations);

            if (!storeExists)
            {
                return;
            }

            int newCustomerId = Customer.AddCustomer(jsonCustomers, customers, storeLocations,
                                                     fName, lName, storeLocationId);

            Console.WriteLine($"Location with id of {newCustomerId} successfully created!");
        }
Beispiel #2
0
        public static void GetDataAndAddOrder(string jsonLocations,
                                              string jsonCustomers,
                                              string jsonOrders,
                                              List <Customer> customers,
                                              List <Location> storeLocations,
                                              List <Order> orders)
        {
            ILogger logger = LogManager.GetCurrentClassLogger();

            int storeLocationId = ConsoleRead.GetStoreLocation(storeLocations,
                                                               "Please enter a valid store Id for the order:");

            if (storeLocationId == -1)
            {
                return;
            }
            bool storeExists = Location.CheckStoreExists(storeLocationId, storeLocations);

            if (!storeExists)
            {
                logger.Error($"{storeLocationId} is not in the list of stores.");
                return;
            }
            int customerId = ConsoleRead.GetCustomer(customers);

            if (customerId == -1)
            {
                return;
            }
            bool customerExists = Customer.CheckCustomerExists(customerId, customers);

            if (!customerExists)
            {
                logger.Error($"{customerId} is not in the list of customers.");
                return;
            }
            Cupcake cupcakeTuple = ConsoleRead.GetCupcake();

            if (cupcakeTuple.Item2 is null)
            {
                return;
            }
            int orderQnty = ConsoleRead.GetCupcakeQuantity();

            if (orderQnty == -1)
            {
                return;
            }
            bool qntyAllowed = Cupcake.CheckCupcakeQuantity(orderQnty);

            if (!qntyAllowed)
            {
                Console.WriteLine("Maximum order quantity is 500.");
                return;
            }
            bool cupcakeAllowed = Cupcake.CheckCupcake(storeLocationId, cupcakeTuple.Item1, orders);

            if (!cupcakeAllowed)
            {
                Console.WriteLine("This store has exhausted supply of that cupcake. Try back in 24 hours.");
                return;
            }
            bool orderFeasible = Order.CheckOrderFeasible(storeLocationId, storeLocations,
                                                          cupcakeTuple.Item2, orderQnty);

            if (!orderFeasible)
            {
                Console.WriteLine("This store does not have enough ingredients to place the requested order.");
                return;
            }
            bool customerCanOrder = Order.CheckCustomerCanOrder(customerId,
                                                                storeLocationId, customers);

            if (!customerCanOrder)
            {
                Console.WriteLine("Customer can't place an order at this store because it hasn't been 2 hours yet.");
                return;
            }

            int newOrderId = Order.AddOrder(storeLocationId, customerId, cupcakeTuple.Item1, cupcakeTuple.Item2, orderQnty,
                                            jsonLocations, jsonCustomers, jsonOrders, customers, storeLocations, orders);

            Console.WriteLine($"Order with id of {newOrderId} successfully created!");
        }