public async Task <IActionResult> AddOrEdit(LoanViewModel loanView) { if (ModelState.IsValid) { if (loanView.Id == null) { var loan = new Loan() { LoanCategoryId = loanView.LoanCategoryId, LoanCompanyId = loanView.LoanCompanyId, InterestRate = loanView.InterestRate, MaximumAmount = loanView.MaximumAmount, MinimumAmount = loanView.MinimumAmount, Moratorium = loanView.Moratorium, }; await _loanRepository.AddLoan(loan); } else { var loan = await _loanRepository.GetLoan(loanView.Id); loan.LoanCompanyId = loanView.LoanCompanyId; loan.LoanCategoryId = loanView.LoanCategoryId; loan.InterestRate = loanView.InterestRate; loan.MinimumAmount = loanView.MinimumAmount; loan.MaximumAmount = loanView.MaximumAmount; loan.Moratorium = loanView.Moratorium; await _loanRepository.UpdateLoan(loan); } return(RedirectToAction(nameof(Index))); } return(View(loanView)); }
public int AddLoan(int userID, int bookID) { try { return(loanRepository.AddLoan(userID, bookID)); } catch (Exception ex) { throw ex; } }
public ActionResult <Loan> AddLoan(Loan item) { string errorString; if (_loanValidator.AddLoanIsValid(item, out errorString)) { return(BadRequest(new JsonResult(errorString))); } _loanRepository.AddLoan(item); return(Ok(item)); }
public async Task <ActionResult> Post([FromBody] LoanDto loan) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } Loans newLoan; try { newLoan = _mapper.Map <Loans>(loan); await _loanRepository.AddLoan(newLoan); } catch (Exception) { return(BadRequest()); } return(Created(new Uri("/api/Loans", UriKind.Relative), newLoan)); }
public Loan AddLoan(Loan loan) { Loan newLoan = _loanRepository.AddLoan(loan); return(newLoan); }