Ejemplo n.º 1
0
        /// <summary>
        /// Resolve customer given arguments
        /// </summary>
        /// <param name="args">Parsed user-input arguments</param>
        /// <returns>Resolved customer or throws an exception</returns>
        private Customer ResolveCustomer(List <string> args)
        {
            CRM crm = repository.Get();

            int customerID = int.Parse(args[Index_To_Remove]);

            return(crm.GetCustomer(customerID));
        }
Ejemplo n.º 2
0
        private void AddCustomer(List <string> args)
        {
            CRMRepository crmRepository = (CRMRepository)repository;

            args.Insert(0, crmRepository.GetNextID().ToString()); // Add new ID to arguments

            Customer newCustomer = (Customer)CreateEntity(args);
            CRM      crm         = repository.Get();

            crm.AddCustomer(newCustomer);

            Console.WriteLine("Added new customer {0} {1} (ID = {2}) to the MRRC CRM.", newCustomer.firstName, newCustomer.lastName, newCustomer.ID);
            Console.WriteLine();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Validate business logic surrounding customers
        /// </summary>
        /// <param name="existingCustomer">Customer to update parameters on</param>
        /// <param name="validatedCustomer">Customer to update parameters from</param>
        private void ValidateConstraints(Customer existingCustomer, Customer validatedCustomer)
        {
            CRM crm = repository.Get();

            if (validatedCustomer.ID != existingCustomer.ID)
            {
                Customer newIdCustomer = crm.FindCustomer(validatedCustomer.ID);
                if (newIdCustomer != null)
                {
                    throw new CustomerAlreadyExistsException(string.Format("Customer with ID {0} already exists. Please choose a different ID.",
                                                                           existingCustomer.ID));
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Rents a vehicle based on user input
        /// </summary>
        /// <param name="args">List of user-input arguments</param>
        protected override void Execute(List <string> args)
        {
            // Setup variables
            int             customerID      = int.Parse(args[0]);
            string          vehicleRego     = args[1];
            int             days            = int.Parse(args[2]);
            FleetRepository fleetRepository = (FleetRepository)repository;
            Fleet           fleet           = fleetRepository.Get();
            CRM             crm             = crmRepository.Get();

            // Resolve
            Vehicle  vehicle  = fleet.GetVehicle(vehicleRego);
            Customer customer = crm.GetCustomer(customerID);

            // Inform user of cost with lots of details
            Console.WriteLine("Rent {0} to {1} {2} (ID: {3}) for {4} days.", vehicle.vehicleRego, customer.firstName, customer.lastName, customer.ID,
                              days);
            Console.WriteLine("This vehicle has a daily cost of ${0}, bringing the total to ${1:0.00}.", vehicle.dailyRate,
                              (vehicle.dailyRate * days));
            Console.WriteLine();

            // Make user confirm rental at price
            string input = "";

            do
            {
                Console.Write("Confirm you want to go ahead with this rental (y/n): ");
                input = Console.ReadLine().Trim().ToLower();
                if (input == "y")
                {
                    break;
                }
                if (input == "n")
                {
                    return;
                }
            } while (input != "y" || input != "n");

            // Let user know it was successful
            Console.WriteLine();
            fleet.RentVehicle(vehicle.vehicleRego, customer.ID);
            Console.WriteLine("Successfully rented a {0} {1} {2} to {3} {4} (ID: {5})", vehicle.year, vehicle.make, vehicle.model,
                              customer.firstName, customer.lastName, customer.ID);
            Console.WriteLine();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Deletes customer and outputs result to user
        /// </summary>
        /// <param name="args">List of user-input arguments</param>
        protected override void Execute(List <string> args)
        {
            CRM crm = repository.Get();

            int      customerID = int.Parse(args[Index_To_Use]);
            Customer customer   = ResolveCustomer(customerID);

            // Ensure customer isn't renting
            Fleet fleet = fleetRepository.Get();

            if (fleet.IsCustomerRenting(customer.ID))
            {
                throw new CustomerCurrentlyRentingException(string.Format("Customer with ID {0} is currently renting a vehicle and " +
                                                                          "cannot be deleted", customerID));
            }

            crm.RemoveCustomer(customer);

            Console.WriteLine("Successfully removed customer {0} {1} (ID = {2}) from the MRRC CRM.", customer.firstName, customer.lastName, customer.ID);
            Console.WriteLine();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Hard resolve customer
        /// </summary>
        /// <param name="customerID"></param>
        /// <returns>Customer or throws an exception if the customer does not exist</returns>
        private Customer ResolveCustomer(int customerID)
        {
            CRM crm = repository.Get();

            return(crm.GetCustomer(customerID));
        }