Example #1
0
        public IActionResult ReturnList(string bookIdent)
        {
            string userId     = _userManager.GetUserId(User);
            Loan   localLoan  = _loanRepository.GetLoanByBookIdent(bookIdent);
            Book   localBook  = _bookRepository.GetBookByIdent(bookIdent);
            var    overdueFee = _loanRepository.CalcOverdue(localLoan.LoanId, userId);

            var Returned = false;

            Returned = _loanRepository.EndLoan(localLoan.LoanBookIdent, userId);

            string loanMessage = null;

            if (Returned == true)
            {
                loanMessage = "'" + localBook.Name + "' was Successfully Returned";
            }
            else
            {
                loanMessage = "Return of  " + localBook.Name + " was Unsuccessful";
            }

            if (overdueFee > 0)
            {
                int euros = ((int)overdueFee / 100);
                int cents = ((int)overdueFee % 100);
                loanMessage = loanMessage +
                              "An Overdue fee of " + euros + "," + cents + "€  will apply";
            }

            var userLoans        = _loanRepository.GetCurrentLoansByUserId(userId);
            var loansWithDetails = new List <LoanWithBookDetails>();

            foreach (var loan in userLoans)
            {
                var loanPlusDetails = new LoanWithBookDetails();
                // var loanPlusDetails = _appDbContext.LoansWithBookDetails;

                loanPlusDetails.BookId     = loan.LoanBookId;
                loanPlusDetails.BookIdent  = loan.LoanBookIdent;
                loanPlusDetails.BorrowDate = loan.BorrowDate;
                DateTime tempScheduleReturnDate = loan.ScheduleReturnDate;
                loanPlusDetails.ScheduleReturnDate = tempScheduleReturnDate.Date;
                loanPlusDetails.TimesRenewed       = loan.TimesRenewed;

                var bookDetails = _bookRepository.GetBookByIdent(loan.LoanBookIdent);
                loanPlusDetails.Name                  = bookDetails.Name;
                loanPlusDetails.Author                = bookDetails.Author;
                loanPlusDetails.Description           = bookDetails.Description;
                loanPlusDetails.BookCoverThumbnailUrl = bookDetails.BookCoverThumbnailUrl;

                loansWithDetails.Add(loanPlusDetails);
            }

            var returnViewModel = new ReturnViewModel()
            {
                LoanReturnList = loansWithDetails,
                LoanMessage    = loanMessage
            };

            return(View(returnViewModel));
        }