Example #1
0
        public async Task <ActionResult <LoanCreatedModel> > CreateLoan(CreateLoanModel model)
        {
            var command = model.ToCommand();
            var receipt = await createLoanCommandHandler.Handle(command);

            return(new LoanCreatedModel
            {
                LoanId = receipt.AggregateId
            });
        }
        public ActionResult Create(CreateLoanModel loan)
        {
            var context  = new BusinessDomain.Classes.Context();
            int memberID = context.Members.ToList().Find(member => member.FirstName == loan.FirstName && member.LastName == loan.LastName).MemberID;
            int bookID   = context.Books.ToList().Find(book => book.Title == loan.BookTitle).BookID;

            context.Loans.Add(new BusinessDomain.Classes.Classes.Loan
            {
                MemberID      = memberID,
                BookID        = bookID,
                LoanIssueDate = DateTime.Today
            });
            context.SaveChanges();
            return(RedirectToAction("LoanBook"));
        }
        public async Task <IActionResult> AcceptLoanRequest(int id, [FromBody] CreateLoanModel model)
        {
            var loanRequest = await _repo.GetById <LoanRequest>(id);

            if (loanRequest.Status != LoanRequestStatus.Pending)
            {
                throw new AppException("Bank Account already evaluated");
            }

            loanRequest.Status = LoanRequestStatus.Accepted;
            var requestAction = await EvaluateLoanRequest(id, ActionType.Accept);

            await _repo.Add(requestAction);

            await CreateLoan(model);

            return(Ok(requestAction));
        }
        public async Task <IActionResult> CreateLoan([FromBody] CreateLoanModel model)
        {
            var loan = await _repo.GetByIdWithInclude <Loan>(model.LoanId, o => o.LoanType);

            var customer = await _repo.GetWithWhere <Customer>(o => o.CNP == model.CustomerCNP);

            var create_model = new CreateBankAccountModel
            {
                AccountType    = 4,
                InitialDeposit = 10000,
            };
            var bankAccount = await _bankRepo.CreateAccount(create_model, customer.UserId.ToString());

            bankAccount.InterestRate = loan.InterestRate;
            bankAccount.Period       = loan.Period;
            var bank = await _repo.Add <BankAccount>(bankAccount);

            return(Ok(bank));
        }