public IActionResult RenewList(string bookIdent) { string userId = _userManager.GetUserId(User); var localLoan = _loanRepository.GetLoanByBookIdent(bookIdent); var localBook = _bookRepository.GetBookByIdent(bookIdent); var overdueFee = _loanRepository.CalcOverdue(localLoan.LoanId, userId); var renewed = false; var canRenew = false; var renewalNotTooSoon = true; bool tempTextColRed = false; bool recentBorrow = false; var timesRenewed = localLoan.TimesRenewed; if (timesRenewed < 5) { canRenew = true; } if (localLoan.LatestRenewDate.AddDays(7) > DateTime.Now) { renewalNotTooSoon = false; if (localLoan.LatestRenewDate == localLoan.BorrowDate) { recentBorrow = true; } } if ((canRenew == true) && (renewalNotTooSoon == true)) { renewed = _loanRepository.RenewLoan(localLoan.LoanBookIdent, userId); } var loanMessage = ""; if (renewed == true) { loanMessage = "'" + localBook.Name + "' was Renewed Successfully"; if (overdueFee > 0) { int euros = ((int)overdueFee / 100); int cents = ((int)overdueFee % 100); loanMessage = loanMessage + "An Overdue fee of " + euros + "," + cents + "€ will apply"; } } else if ((renewed == false) && (canRenew == true) && (renewalNotTooSoon == true)) { loanMessage = "Loan Renewal was Unsuccessful"; tempTextColRed = true; } else if ((canRenew == false) && (renewalNotTooSoon == true)) { loanMessage = "Loan Renewal was Unsuccessful. This book has been Renewed a Maximum 5 times"; if (overdueFee > 0) { int euros = ((int)overdueFee / 100); int cents = ((int)overdueFee % 100); loanMessage = loanMessage + "An Overdue fee of " + euros + "," + cents + "€ will apply"; } tempTextColRed = true; } else if ((canRenew == true) && (renewalNotTooSoon == false) && recentBorrow == false) { loanMessage = "Loan Renewal was Unsuccessful. This book was Renewed less than 1 week ago"; tempTextColRed = true; } else if ((canRenew == true) && (renewalNotTooSoon == false) && recentBorrow == true) { loanMessage = "Loan Renewal was Unsuccessful. This book was Borrowed less than 1 week ago"; tempTextColRed = true; } 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.UserId = loan.UserId; 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 renewViewModel = new RenewViewModel() { LoanRenewList = loansWithDetails, LoanMessage = loanMessage, TextColorRed = tempTextColRed }; return(View(renewViewModel)); }
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)); }