/// <summary> /// Always Apply Retry pattern to make it more resilient /// </summary> private async Task CompensateIfRequired(WorkShopManagementNewVM inputModel, HttpResponseMessage httpResponse) { _logger.LogInformation("SAGA - CompensateIfRequired called"); if (httpResponse.StatusCode == HttpStatusCode.OK) { return; } _logger.LogInformation($"SAGA - httpResponse.StatusCode{httpResponse.StatusCode}"); if (IsVehicleApiRequest(httpResponse)) { _logger.LogInformation("SAGA - IsVehicleApiRequest:true"); HttpResponseMessage customerUndoResponse = await _policy .ExecuteAsync(() => _customerAPI.UndoRegister(inputModel.Customer.EmailAddress)); } else if (IsWorkshopApiRequest(httpResponse)) { _logger.LogInformation("SAGA - IsWorkshopApiRequest:true"); HttpResponseMessage vehicleUndoResponse = await _policy .ExecuteAsync(() => _vehicleAPI.UndoRegister(inputModel.Vehicle.LicenseNumber)); HttpResponseMessage customerUndoResponse = await _policy .ExecuteAsync(() => _customerAPI.UndoRegister(inputModel.Customer.EmailAddress)); } }
public IActionResult New() { var model = new WorkShopManagementNewVM { Customer = new CustomerRegisterVM() }; return(View(model)); }
public async Task <IActionResult> RegisterAndPlanMaintenanceJob([FromForm] WorkShopManagementNewVM inputModel) { if (ModelState.IsValid) { string emailAddress = inputModel.Customer.EmailAddress; string licenseNumber = inputModel.Vehicle.LicenseNumber; HttpResponseMessage customerResponse = await _customerAPI.Register(inputModel.Customer); if (ShowErrorIfRequired(customerResponse, out var customerError)) { return(customerError); } HttpResponseMessage vehicleApiResponse = await _vehicleAPI.Register(inputModel.Vehicle, emailAddress); await CompensateIfRequired(inputModel, vehicleApiResponse); if (ShowErrorIfRequired(vehicleApiResponse, out var vehicleError)) { return(vehicleError); } HttpResponseMessage workShopApiResponse = await _workshopAPI.RegisterPlanning(inputModel.MaintenanceJob, emailAddress, licenseNumber); await CompensateIfRequired(inputModel, workShopApiResponse); if (ShowErrorIfRequired(workShopApiResponse, out var workShopError)) { return(workShopError); } await Notify(emailAddress); TempData["SuccessMessage"] = "Success! Please check your email to see the Maintenance Job Detail."; return(RedirectToAction("Index")); } else { return(View("New", inputModel)); } }