public Result CheckOut(int bookId, int lendeeId) { var book = bookRepository.GetById(bookId); if (book == null) { return(Result.Error("Invalid bookId passed in")); } var lendee = lendeeRepository.GetById(lendeeId); if (lendee == null) { return(Result.Error("Invalid lendeeId passed in")); } var currentLoan = loanRepository.GetCurrent(bookId); if (currentLoan != null) { return(Result.Error("This book is already on loan")); } loanRepository.Create(new Loan { BookId = bookId, LendeeId = lendeeId, LentOn = DateTime.Today, IsReturned = false }); return(Result.Success("Check out was successful")); }
public async Task <Guid> Create(LoanModel loanModel) { loanModel.LoanStatus = LoanStatus.InProcess; Guid loanId = await _loansRepository.Create(loanModel); return(loanId); }
public async Task Create(Loan loan) { if (loan == null) { throw new LoanCreateException("Empréstimo não pode ser nulo"); } await loanRepository.Create(loan); }
public Loan LoanBook(Student student, Book book) { if (book.AvailableQuantity == 0) { throw new InvalidOperationException("Book unavailable."); } var dueDate = DateTime.Now; var loan = new Loan(new Guid(), book, student, dueDate, dueDate.AddDays(returnDate)); return(loanRepository.Create(loan)); }
public async Task <int> Handle(CreateLoanCommand request, CancellationToken cancellationToken) { Loan loan = new Loan { AccountId = request.Loan.AccountId, Date = request.Loan.Date, Amount = request.Loan.Amount, Duration = request.Loan.Duration, Payments = request.Loan.Payments, Status = request.Loan.Status, Granted = request.Loan.Granted }; await _repository.Create(loan); return(loan.LoanId); }
public async Task <bool> Borrow(Guid userId, Guid bookId) { if (!await UserHasLessThanTwoBooksBorrowed(userId)) { return(false); } if (await UserHasAlreadyBorrowedACopyOfTheSameBook(userId, bookId)) { return(false); } return(await _loanRepository.Create( new Domain.Entities.LoanEntity { BookId = bookId, UserId = userId })); }
public async Task <Unit> Handle(CreateLoanCommand request, CancellationToken cancellationToken) { int customerId = await _userRepository.GetCustomerId(); Account account = await _accountRepository.GetSingle(request.AccountId); Loan loan = new Loan { AccountId = account.AccountId, Date = DateTime.Now, Amount = request.Amount, Duration = request.Duration, Payments = (request.Amount / request.Duration), Status = "Under review", Granted = false }; await _loanRepository.Create(loan); return(Unit.Value); }
public Loan Create(Loan loan) { Client client = loan.Client; Loan newLoan; SetMissingValues(loan); if (IsDeadlineAfterApprovalDate(loan)) { SetNumberOfInstallments(loan); SetInstallmentAmount(loan); ApproveLoan(loan); _clientService.Update(client); newLoan = _loanRepository.Create(loan); newLoan.Client = client; return(newLoan); } else { throw new InvalidDateException(string.Format(INVALID_DATE_ERROR, loan.Deadline, loan.ApprovalDate)); } }