public async Task <(bool Success, string Error, CreateMortgageRateViewModel Model)> GetCreateMortgageRateViewModelAsync() { var success = false; var error = ""; CreateMortgageRateViewModel model = new CreateMortgageRateViewModel(); try { var rate = await _mortgageRepository.FetchMortgageRateAsync(); if (rate != null) { model.Rate = rate.Rate; } success = true; } catch (Exception ex) { error = "Unexpected error occurred while processing your request"; _logger.LogError("MortgageService.GetCreateMortgageRateViewModelAsync - exception:{@Ex}", new object[] { ex }); } return(success, error, model); }
public async Task <IActionResult> MortgageRate(CreateMortgageRateViewModel model) { _logger.LogInformation(GetLogDetails()); var userId = _userManager.GetUserId(User); var result = await _mortgageService.SaveMortgageRateAsync(model, userId); if (result.Success) { SetSiteMessage(MessageType.Success, DisplayFor.FullRequest, "Mortgage rate has been saved successfully."); } else { SetSiteMessage(MessageType.Error, DisplayFor.FullRequest, result.Error); } return(RedirectToAction(nameof(Index))); }
public async Task <(bool Success, string Error)> SaveMortgageRateAsync(CreateMortgageRateViewModel model, string userId) { var success = false; var error = ""; try { var rate = await _mortgageRepository.FetchMortgageRateAsync(); if (rate == null) { rate = new MortgageRate { CreatedUtc = DateTime.UtcNow, CreatedUserId = userId }; } else { rate.AuditUserId = userId; rate.AuditUtc = DateTime.UtcNow; } rate.Rate = model.Rate; await _mortgageRepository.SaveMortgageRateAsync(rate); success = true; } catch (Exception ex) { error = "Unexpected error occurred while processing your request"; _logger.LogError("MortgageService.SaveMortgageRateAsync - exception:{@Ex}", new object[] { ex }); } return(success, error); }