Пример #1
0
        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));
        }
Пример #2
0
 public int AddLoan(int userID, int bookID)
 {
     try
     {
         return(loanRepository.AddLoan(userID, bookID));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #3
0
        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));
        }
Пример #4
0
        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));
        }
Пример #5
0
        public Loan AddLoan(Loan loan)
        {
            Loan newLoan = _loanRepository.AddLoan(loan);

            return(newLoan);
        }