public async Task <GetAppointmentSlotsResponse> GetAppointmentSlots(GetAppointmentSlotsRequest getAppointmentSlotsRequest) { if (getAppointmentSlotsRequest == null) { throw new ArgumentNullException(nameof(getAppointmentSlotsRequest)); } var validateMessages = _validateRequest.ValidateRequestData(getAppointmentSlotsRequest); if (validateMessages != null) { throw new InvalidRequestException(validateMessages.AsEnumerable().ToList()); } var customer = _cdkCustomerDAL.GetCdkCustomer(getAppointmentSlotsRequest.CommunityId, getAppointmentSlotsRequest.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, getAppointmentSlotsRequest.RooftopId); _telemetryClient?.TrackDependency("CDKAutolineService", "GetCustomerToken", customer.CustomerLoginId, startTime, timer.Elapsed, customerToken != null); startTime = DateTime.Now; timer = System.Diagnostics.Stopwatch.StartNew(); var cdkGetAppointmentSlotsRequest = MapAppointmentSlots(getAppointmentSlotsRequest); var getServiceAdvisorsResponse = await RequestGetAppointmentSlots(cdkGetAppointmentSlotsRequest, getAppointmentSlotsRequest.CommunityId, customer.CustomerLoginId, customerToken); _telemetryClient?.TrackDependency("CDKAutolineService", "GetAppointmentSlots", JsonConvert.SerializeObject(cdkGetAppointmentSlotsRequest), startTime, timer.Elapsed, getServiceAdvisorsResponse != null); if (getServiceAdvisorsResponse == null || !getServiceAdvisorsResponse.Success) { var cdkAutolineException = new CDKAutolineException(UtilityHelper.SerializeObject(getServiceAdvisorsResponse?.Errors)); _telemetryClient?.TrackException(cdkAutolineException); throw cdkAutolineException; } return(getServiceAdvisorsResponse.Result as GetAppointmentSlotsResponse); }
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 async Task <string> RequestAndActivateAppToken(DealerCDKConfiguration dealerCDKConfig, string communityId, AppToken appToken, bool isTokenFetchedFromDb) { string token; if (!isTokenFetchedFromDb) { var requestApiResponse = await RequestToken(dealerCDKConfig, communityId); if (requestApiResponse.Result == null || !requestApiResponse.Success || !(requestApiResponse.Result is TokenResponse objRequestToken)) { var cdkAutolineException = new CDKAutolineException(UtilityHelper.SerializeObject(requestApiResponse.Errors)); _telemetryClient?.TrackException(cdkAutolineException); throw cdkAutolineException; } token = objRequestToken.Token; } else { token = appToken.Token.ToString(); } //Activate Token from generated token. var activeApiTokenResponse = await ActivateToken(communityId, token, dealerCDKConfig.PartnerKey); if (activeApiTokenResponse == null || !activeApiTokenResponse.Success) { if (isTokenFetchedFromDb) { return(null); } var cdkAutolineException = new CDKAutolineException(UtilityHelper.SerializeObject(activeApiTokenResponse?.Errors)); _telemetryClient?.TrackException(cdkAutolineException); throw cdkAutolineException; } return(token); }
internal async Task <string> RequestAndActivateCustomerToken(CdkCustomer cdkCustomer, DealerCDKConfiguration dealerCDKConfig, string roofTopId, Guid?existingToken) { if (existingToken == null) { var requestApiResponse = await RequestToken(dealerCDKConfig, cdkCustomer.CommunityId, cdkCustomer.CustomerLoginId); if (requestApiResponse.Result == null || !requestApiResponse.Success || !(requestApiResponse.Result is TokenResponse objRequestToken) || string.IsNullOrWhiteSpace(objRequestToken.Token)) { var cdkAutolineException = new CDKAutolineException(UtilityHelper.SerializeObject(requestApiResponse.Errors)); _telemetryClient?.TrackException(cdkAutolineException); throw cdkAutolineException; } cdkCustomer.Token = new Guid(objRequestToken.Token); } //Activate Token from generated token. var checkPasswordApiResponse = await _customerService.CheckPassword(new CustomerVerifyRequest { CommunityId = cdkCustomer.CommunityId, CustomerNo = cdkCustomer.CustomerNo, RoofTopId = roofTopId }, cdkCustomer, dealerCDKConfig.PartnerKey); if (checkPasswordApiResponse == null || !checkPasswordApiResponse.Success) { if (existingToken != null) { return(null); } throw new CDKAutolineException(UtilityHelper.SerializeObject(checkPasswordApiResponse?.Errors)); } await _cdkCustomerService.SaveCdkCustomer(cdkCustomer); return(cdkCustomer.Token.ToString()); }