public async Task <ApiResponse <ValidationResultModel> > ValidateChangeSalaryAsync( string accessToken, InsuredPersonModel insuredPersonModel, CancellationToken cancellationToken) { if (insuredPersonModel == null) { throw new ArgumentNullException(nameof(insuredPersonModel)); } HttpResponseMessage response = await SendApiRequestAsync( accessToken, $"/contract/{insuredPersonModel.ContractId}/insured-person/{insuredPersonModel.InsuredPersonId}/salary/validation", HttpMethod.Post, new { effectiveAnnualSalary = insuredPersonModel.AnnualSalary, employmentRate = insuredPersonModel.EmploymentRate, dueDate = DateTime.Now, }, cancellationToken : cancellationToken); string validationResponseContent = await response.Content.ReadAsStringAsync(); ValidationResultModel validationResultModel = JsonConvert.DeserializeObject <ValidationResultModel>(validationResponseContent); return(new ApiResponse <ValidationResultModel>(validationResultModel)); }
public async Task <IActionResult> ChangeSalary( InsuredPersonModel insuredPersonModel, CancellationToken cancellationToken = default) { string accessToken = await HttpContext.GetTokenAsync("access_token"); // we could execute a validation before sending the request. ApiResponse <ValidationResultModel> validationResult = await slkvPartnerApiClient.ValidateChangeSalaryAsync( accessToken, insuredPersonModel, cancellationToken); if (!validationResult.SuccessData.IsValid) { foreach (ValidationMemberModel member in validationResult.SuccessData.Members) { ModelState.AddModelError(member.Member, string.Join(", ", member.Errors.Select(error => error.Code))); } return(View("ChangeSalaryForm", insuredPersonModel)); } // okay, now we send the request to start the business process. ApiResponse executionResult = await slkvPartnerApiClient.StartChangeSalaryAsync( accessToken, insuredPersonModel, cancellationToken); if (executionResult.Successful) { return(View()); } return(ViewError(executionResult.FailureStatusCode)); }
public async Task <ApiResponse> StartChangeSalaryAsync( string accessToken, InsuredPersonModel insuredPersonModel, CancellationToken cancellationToken) { if (insuredPersonModel == null) { throw new ArgumentNullException(nameof(insuredPersonModel)); } HttpResponseMessage response = await SendApiRequestAsync( accessToken, $"/contract/{insuredPersonModel.ContractId}/insured-person/{insuredPersonModel.InsuredPersonId}/salary", HttpMethod.Post, new { effectiveAnnualSalary = insuredPersonModel.AnnualSalary, employmentRate = insuredPersonModel.EmploymentRate, dueDate = DateTime.Now, }, cancellationToken : cancellationToken); if (response.IsSuccessStatusCode) { return(new ApiResponse()); } return(new ApiResponse(response.StatusCode)); }
public IActionResult ChangeSalaryForm( InsuredPersonModel insuredPersonModel) { return(View(insuredPersonModel)); }