Esempio n. 1
0
        public async Task <CreateServiceBookingResponse> CreateServiceBooking(CreateServiceBookingRequest request,
                                                                              DealerConfigurationResponse dealerConfigurationResponse)
        {
            if (dealerConfigurationResponse.RooftopId == null)
            {
                throw new ArgumentNullException(nameof(dealerConfigurationResponse.RooftopId));
            }
            if (dealerConfigurationResponse.CommunityId == null)
            {
                throw new ArgumentNullException(nameof(dealerConfigurationResponse.CommunityId));
            }

            var customer = _customerVehicleDal.GetCustomer(request.CustomerNo, dealerConfigurationResponse.RooftopId, dealerConfigurationResponse.CommunityId);

            if (customer == null)
            {
                throw new InvalidCustomerException(ExceptionMessages.InvalidCustomer);
            }

            var customerVehicle = _customerVehicleDal.GetCustomerVehicle(customer.Id, request.VehicleNo);

            if (customerVehicle == null)
            {
                throw new InvalidCustomerException(ExceptionMessages.InvalidCustomerVehicle);
            }

            var cdkCreateServiceBookingRequest = MapCreateServiceBookingRequest(customer, customerVehicle, request);
            var serviceBookingResponse         = await _customerServiceBooking.CreateServiceBooking(cdkCreateServiceBookingRequest);

            var serviceBooking = MapServiceBooking(request, serviceBookingResponse);
            await _customerVehicleDal.SaveServiceBooking(serviceBooking);

            return(serviceBookingResponse);
        }
        internal async Task <CommunicationMethod> SendInvite(SaveCustomerVehicleRequest request,
                                                             DealerConfigurationResponse dealerConfigResponse, CommunicationMethod method)
        {
            var dealerInvitationResponse = await _dealerConfigurationService.GetDealerInvitationContent(dealerConfigResponse.RooftopId, dealerConfigResponse.CommunityId);

            if (dealerInvitationResponse == null)
            {
                throw new DealerInvitationContentException();
            }

            switch (method)
            {
            case CommunicationMethod.Email:     // Send invitation via email.
                return(await SendEmailWithOtherOption(request, dealerConfigResponse, dealerInvitationResponse));

            case CommunicationMethod.SmsOrEmail:
            {
                if (!string.IsNullOrEmpty(request.PhoneNumber))
                {
                    return(await SendSmsWithOtherOption(request, dealerConfigResponse, dealerInvitationResponse, true));
                }
                return(await SendEmailWithOtherOption(request, dealerConfigResponse, dealerInvitationResponse));
            }

            case CommunicationMethod.EmailOrSms:
                return(await SendEmailWithOtherOption(request, dealerConfigResponse, dealerInvitationResponse, true));

            case CommunicationMethod.Sms:     // Send invitation via sms.
                return(await SendSmsWithOtherOption(request, dealerConfigResponse, dealerInvitationResponse));

            default:
                return(CommunicationMethod.None);
            }
        }
 public void SetUp()
 {
     _fixture                                 = new Fixture().Customize(new AutoMoqCustomization());
     _restfulClientMock                       = _fixture.Freeze <Mock <IRestfulClient> >();
     _getRecommendedServicesRequest           = _fixture.Create <GetRecommendedServicesRequest>();
     _getRecommendedServicesRequest.ModelYear = "2017";
     _dealerConfigurationResponse             = _fixture.Create <DealerConfigurationResponse>();
     _underTest                               = _fixture.Create <CDKAutolineService>();
 }
        internal async Task <(bool, Exception)> SendSmsOrEmail(SaveCustomerVehicleRequest request,
                                                               DealerConfigurationResponse dealerResponse, DealerInvitationContentResponse dealerInvitationResponse, bool sendEmail = false)
        {
            if (sendEmail)
            {
                return(await _emailGatewayClient.SendHtmlEmail(dealerResponse.EmailAddress, request.CustomerEmail, dealerInvitationResponse.EmailSubject,
                                                               GetInvitationText(dealerResponse.DealerId, request.CustomerNo, request.VehicleNo, request.RegistrationNo, dealerInvitationResponse.EmailContent)));
            }

            var phoneNumber = FormatInternationalMobileNumber(request.PhoneNumber);

            return(_smsGatewayClient.SendMessage(_invitationFromPhone, phoneNumber,
                                                 GetInvitationText(dealerResponse.DealerId, request.CustomerNo, request.VehicleNo, request.RegistrationNo, dealerInvitationResponse.SmsContent)));
        }
        public bool ValidateEmailOrSmsByCommunicationMethod(DealerConfigurationResponse response, string phoneNumber, string email)
        {
            var method = GetCommunitcationMethod(response.CommunicationMethod);

            switch (method)
            {
            case CommunicationMethod.Sms:
            {
                if (string.IsNullOrEmpty(phoneNumber))
                {
                    throw new PhoneOrEmailNullException("phone number is mandatory to process the request");
                }
                return(true);
            }

            case CommunicationMethod.Email:
            {
                if (string.IsNullOrEmpty(email))
                {
                    throw new PhoneOrEmailNullException("email address is mandatory to process the request");
                }
                return(true);
            }

            case CommunicationMethod.EmailOrSms:
            case CommunicationMethod.SmsOrEmail:
            {
                if (string.IsNullOrEmpty(email) && string.IsNullOrEmpty(phoneNumber))
                {
                    throw new PhoneOrEmailNullException("email or phone number is mandatory to process the request");
                }
                return(true);
            }

            default:
                return(true);
            }
        }
Esempio n. 6
0
        public async Task SaveCustomerVehicle(SaveCustomerVehicleRequest request, DealerConfigurationResponse dealerConfigResponse)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (dealerConfigResponse == null)
            {
                throw new ArgumentNullException(nameof(dealerConfigResponse));
            }

            var customer = MapCustomer(request);

            var customerVehicle = MapCustomerVehicle(request, customer);

            var existingCustomer = _customerVehicleDal.GetCustomer(request.CustomerNo, request.RooftopId, request.CommunityId);

            if (existingCustomer == null)
            {
                //register customer if could not find in database
                // not handlerd if cdk autoline give customer already registered.
                await _customerRegistrationService.Register(customer, customerVehicle);
            }

            var customerId = await _customerVehicleDal.SaveCustomer(customer);

            customerVehicle.CustomerId = customerId;
            await _customerVehicleDal.SaveCustomerVehicle(customerVehicle);

            var communicationMethod       = GetCommunicationMethod(dealerConfigResponse.CommunicationMethod);
            var inviteCommunicationMethod = await _customerInvitationService.Invite(request, dealerConfigResponse, communicationMethod);

            var invitation = MapInvitation(request, dealerConfigResponse.DealerId, dealerConfigResponse.CommunicationMethod, inviteCommunicationMethod);

            invitation.CustomerId = customer.Id;
            await _customerVehicleDal.LogInvitationDetail(invitation);
        }
        internal async Task <CommunicationMethod> SendSmsWithOtherOption(SaveCustomerVehicleRequest request,
                                                                         DealerConfigurationResponse dealerResponse, DealerInvitationContentResponse dealerInvitationResponse, bool sendEmailAsSecondOption = false)
        {
            (bool smsResponse, Exception ex) = await SendSmsOrEmail(request, dealerResponse, dealerInvitationResponse);

            if (!smsResponse)
            {
                if (sendEmailAsSecondOption)
                {
                    _telemetryClient?.TrackException(ex);
                    (bool emailResponse, Exception emailEx) = await SendSmsOrEmail(request, dealerResponse, dealerInvitationResponse, true);

                    if (!emailResponse)
                    {
                        throw emailEx;
                    }
                    return(CommunicationMethod.Email);
                }

                throw ex;
            }

            return(CommunicationMethod.Sms);
        }
Esempio n. 8
0
        internal GetCdkRecommendedServiceRequest MapRecommendedServicesRequest(GetRecommendedServicesRequest request, DealerConfigurationResponse dealer)
        {
            var getCdkRecommendedServiceRequest = _mapper.Map <GetRecommendedServicesRequest, GetCdkRecommendedServiceRequest>(request);

            getCdkRecommendedServiceRequest.EstVehicleAgeMonths = GetEstVehicleAgeMonths(request.ModelYear);

            return(_mapper.Map(dealer, getCdkRecommendedServiceRequest));
        }
Esempio n. 9
0
        public async Task <GetRecommendedServicesResponse> GetRecommendedServices(GetRecommendedServicesRequest request, DealerConfigurationResponse dealer)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (dealer == null)
            {
                throw new ArgumentNullException(nameof(dealer));
            }

            var cdkRecommendedServiceRequest = MapRecommendedServicesRequest(request, dealer);

            var startTime = DateTime.Now;
            var timer     = System.Diagnostics.Stopwatch.StartNew();

            var cdkRecommendedServiceResponse = await _restfulClient.PostAsync <GetCdkRecommendedServiceRequest, CdkRecommendedServicesResponse>(
                GetRecommendedServicesUrl, cdkRecommendedServiceRequest);

            _telemetryClient?.TrackDependency("CDKAutolineService", "GetRecommendedServices",
                                              JsonConvert.SerializeObject(request), startTime,
                                              timer.Elapsed,
                                              cdkRecommendedServiceResponse != null);

            return(MapRecommendedServicesReponse(cdkRecommendedServiceResponse));
        }
 public async Task <CommunicationMethod> Invite(SaveCustomerVehicleRequest saveCustomerVehicleRequest, DealerConfigurationResponse dealerConfigResponse, CommunicationMethod method)
 {
     if (saveCustomerVehicleRequest == null)
     {
         throw new ArgumentNullException(nameof(saveCustomerVehicleRequest));
     }
     return(await SendInvite(saveCustomerVehicleRequest, dealerConfigResponse, method));
 }
Esempio n. 11
0
        public async Task <GetCustomerVehicleResponse> GetCustomerVehicle(int customerNo, int vehicleNo, DealerConfigurationResponse dealerConfigResponse)
        {
            if (dealerConfigResponse == null)
            {
                throw new ArgumentNullException(nameof(dealerConfigResponse));
            }
            if (customerNo <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(customerNo));
            }
            if (vehicleNo <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(vehicleNo));
            }

            var customer = _customerVehicleDal.GetCustomer(customerNo, dealerConfigResponse.RooftopId, dealerConfigResponse.CommunityId);

            if (customer == null)
            {
                return(null);
            }

            var customerVehicle = _customerVehicleDal.GetCustomerVehicle(customer.Id, vehicleNo);

            if (customerVehicle == null)
            {
                return(null);
            }

            if (!_customerInvitationService.ValidateLink(customerVehicle))
            {
                throw new InvitationExpiredException();
            }

            var getCustomerVehicleResponse = _mapper.Map <Customer, GetCustomerVehicleResponse>(customer);

            _mapper.Map(customerVehicle, getCustomerVehicleResponse);

            var verifyCustomerResponse = await _customerRegistrationService.Verify(customer);

            getCustomerVehicleResponse.CdkAutolineToken = verifyCustomerResponse.CDKAutolineToken;
            getCustomerVehicleResponse.CustomerLoginId  = verifyCustomerResponse.CustomerLoginId;
            return(getCustomerVehicleResponse);
        }
Esempio n. 12
0
        public async Task UpdateCustomerContact(UpdateCustomerContactRequest request, DealerConfigurationResponse dealerConfigurationResponse)
        {
            var customer = _customerVehicleDal.GetCustomer(request.CustomerNo, dealerConfigurationResponse.RooftopId, dealerConfigurationResponse.CommunityId);

            if (customer == null)
            {
                throw new InvalidCustomerException(ExceptionMessages.InvalidCustomer);
            }
            await _emailService.SendUpdateCustomerContactEmail(request, customer.CustomerNo, dealerConfigurationResponse.EmailAddress);
        }
Esempio n. 13
0
        public async Task DismissVehicleOwnership(DismissVehicleOwnershipRequest request, DealerConfigurationResponse dealerConfigResponse)
        {
            if (dealerConfigResponse == null)
            {
                throw new ArgumentNullException(nameof(dealerConfigResponse));
            }
            if (request.CustomerNo <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(request.CustomerNo));
            }
            if (request.VehicleNo <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(request.VehicleNo));
            }
            if (request.DealerId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(request.DealerId));
            }

            var customer = _customerVehicleDal.GetCustomer(request.CustomerNo, dealerConfigResponse.RooftopId, dealerConfigResponse.CommunityId);

            if (customer == null)
            {
                throw new InvalidCustomerException(ExceptionMessages.InvalidCustomer);
            }
            var customerVehicle = _customerVehicleDal.GetCustomerVehicle(customer.Id, request.VehicleNo);

            if (customerVehicle == null)
            {
                throw new InvalidCustomerException(ExceptionMessages.InvalidCustomerVehicle);
            }

            await _customerVehicleDal.DeleteCustomerVehicle(customer.Id, customerVehicle.VehicleNo);

            await _emailService.SendDismissVehicleOwnerShipEmail(customer, request, dealerConfigResponse.EmailAddress, customerVehicle.RegistrationNo);
        }