public async Task <Result> AddNewLoan(LoanDto loan) { var result = new Result(); try { var newLoan = _mapper.Map <Loan>(loan); await _repository.AddAsync(newLoan); result.ReturnInsert(newLoan); } catch (Exception e) { result.WithError(e.Message); } return(result); }
public async Task <IActionResult> Borrow(CreateViewModel model) { if (ModelState.IsValid) { var result = await loanRepository.AddAsync(new Loan { Id = Guid.NewGuid(), BookId = model.BookId, BorrowStatus = Status.Requested, BorrowedByUserId = userManager.GetUserId(User) }); //update to redirec to current user borrow history return(RedirectToAction(nameof(Requests))); } return(View(model: model)); }
public async Task AddAsync(Loan loan) { if (await HasPendingReturnsByPeople(loan)) { return; } if (!DateExtepectedIsVaid(loan)) { return; } loan.StatusLoan = DomainParameters.Borrowed; await _loanRepository.AddAsync(loan); if (loan.LoanBooks.Any()) { foreach (var loanBook in loan.LoanBooks) { _loanBookService.AddAsync(loanBook); } } }