Ejemplo n.º 1
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!");
        }
Ejemplo n.º 2
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!");
        }