public async Task <IActionResult> Create(int id, EmploymentLoanRequestViewModel employmentLoanRequest) { var user = await _userManager.GetUserAsync(HttpContext.User); var loanType = await _loanTypeService.GetLoanType(id); try { if (ModelState.IsValid) { await _employmentService.CreateEmployment(employmentLoanRequest.Employment); var employments = await _employmentService.GetEmployments(); var employmentId = employments.OrderByDescending(x => x.Id).FirstOrDefault().Id; await _loanRequestService.CreateLoanRequest(employmentLoanRequest.LoanRequest, loanType, user.Id, employmentId); ViewData[ViewDataKeys.LoanRequestSuccess] = "Loan Request Sent Successfully!"; } } catch (LoanTermOutOfBoundException) { ViewData[ViewDataKeys.LoanTermException] = $"Loan Term must be between {loanType.MinTerm}-{loanType.MaxTerm} months"; } catch (LoanSumOutOfBoundException) { ViewData[ViewDataKeys.LoanSumException] = $"Loan Sum must be between {loanType.MinLoanSum}-{loanType.MaxLoanSum} {loanType.Currency.Name}"; } ViewData[ViewDataKeys.UserAccountId] = new SelectList(await _bankAccountService.GetUserAccounts(user.Id), "Id", "Name"); ViewData[ViewDataKeys.LoanType] = await _loanTypeService.GetLoanType(1); ViewData[ViewDataKeys.EmploymentTypeId] = new SelectList(_employmentTypeService.GetAllTypes(), "Id", "Name"); return(View()); }
public async Task <IEnumerable <Employment> > GetEmployments() { return(await _service.GetEmployments()); }