internal ServiceBookings MapServiceBooking(CreateServiceBookingRequest request, CreateServiceBookingResponse response) { var serviceBooking = _mapper.Map <CreateServiceBookingRequest, ServiceBookings>(request); serviceBooking.CreateTime = DateTime.Today; return(_mapper.Map(response, serviceBooking)); }
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); }
public async Task <CreateServiceBookingResponse> CreateServiceBooking(CreateServiceBookingRequest createServiceBookingRequest) { if (createServiceBookingRequest == null) { throw new ArgumentNullException(nameof(createServiceBookingRequest)); } var customer = _cdkCustomerDAL.GetCdkCustomer(createServiceBookingRequest.CommunityId, createServiceBookingRequest.CustomerNo); if (customer == null) { throw new InvalidCustomerException(ExceptionMessages.InvalidCustomer); } // if token is null then requesting for new token. // Otherwise used the stored token in database. var startTime = DateTime.Now; var timer = System.Diagnostics.Stopwatch.StartNew(); var customerToken = await _tokenService.GetCustomerToken(customer, createServiceBookingRequest.RooftopId); _telemetryClient?.TrackDependency("CDKAutolineService", "GetCustomerToken", customer.CustomerLoginId, startTime, timer.Elapsed, customerToken != null); startTime = DateTime.Now; timer = System.Diagnostics.Stopwatch.StartNew(); var cdkCreateServiceBookingRequest = MapToCdkCreateServiceBookingRequest(createServiceBookingRequest, customer); var cdkCreateServiceBookingResponse = await RequestCreateServiceBooking(cdkCreateServiceBookingRequest, createServiceBookingRequest.CommunityId, customerToken); _telemetryClient?.TrackDependency("CDKAutolineService", "CreateServiceBooking", JsonConvert.SerializeObject(cdkCreateServiceBookingRequest), startTime, timer.Elapsed, cdkCreateServiceBookingResponse != null); if (cdkCreateServiceBookingResponse == null || !cdkCreateServiceBookingResponse.Success) { var cdkAutolineException = new CDKAutolineException(UtilityHelper.SerializeObject(cdkCreateServiceBookingResponse?.Errors)); _telemetryClient?.TrackException(cdkAutolineException); throw cdkAutolineException; } return(cdkCreateServiceBookingResponse.Result as CreateServiceBookingResponse); }
internal CDKCreateServiceBookingRequest MapCreateServiceBookingRequest(Customer customer, CustomerVehicle customerVehicle, CreateServiceBookingRequest request) { var cdkCreateServiceBookingRequest = _mapper.Map <CreateServiceBookingRequest, CDKCreateServiceBookingRequest>(request); _mapper.Map(customer, cdkCreateServiceBookingRequest); _mapper.Map(customerVehicle, cdkCreateServiceBookingRequest); return(cdkCreateServiceBookingRequest); }