Пример #1
0
        /// <summary>
        /// Edits a customer based on user input
        /// </summary>
        /// <param name="args">List of user-input arguments</param>
        protected override void Execute(List <string> args)
        {
            PropertyInfo[] customerProperties = typeof(Customer).GetProperties();

            Customer      existingCustomer = ResolveCustomer(args);
            List <string> trimmedArgs      = TrimArguments(args);

            DefaultArguments(ref trimmedArgs, customerProperties, existingCustomer);

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

            if (fleet.IsCustomerRenting(existingCustomer.ID))
            {
                throw new CustomerCurrentlyRentingException(string.Format("This customer is currently renting a vehicle and " +
                                                                          "cannot be edited", existingCustomer));
            }

            Customer validatedCustomer = CreateNewCustomer(trimmedArgs);

            ValidateConstraints(existingCustomer, validatedCustomer);
            EqualiseCustomers(existingCustomer, validatedCustomer);

            Console.WriteLine("Successfully edited customer {0} {1} (ID = {2}).", validatedCustomer.firstName, validatedCustomer.lastName,
                              validatedCustomer.ID);
            Console.WriteLine();
        }
Пример #2
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();
        }