public ActionResult Borrow() { string s = System.Web.HttpContext.Current.Session["UserID"].ToString(); int UID = int.Parse(s); BorrowListViewModel bvml = new BorrowListViewModel(); BorrowBusinessLayer bbl = new BorrowBusinessLayer(); List <Borrow> b = bbl.GetBorrowList(UID); bvml.borrows = BorrowSealed(b); return(View("Borrow", bvml)); }
public IActionResult BorrowList() { // get the userId and their loans if any string userId = _userManager.GetUserId(User); List <Loan> userLoans = _loanRepository.GetCurrentLoansByUserId(userId).ToList(); var userLoansTotal = userLoans.Count(); // prepare a message for the user advising them of their loan status var loansLeft = (5 - userLoansTotal); switch (userLoansTotal) { case int i when i == 0: _loansMessage = "You currently have " + userLoansTotal + " loans. You may borrow up to " + loansLeft + " books."; break; case int i when i == 1: _loansMessage = "You currently have " + userLoansTotal + " loan. You may borrow another " + loansLeft + " more books."; break; case int i when i > 1 && i <= 3: _loansMessage = "You currently have " + userLoansTotal + " loans. You may borrow another " + loansLeft + " more books."; break; case int i when i == 4: _loansMessage = "You currently have " + userLoansTotal + " loans. You may borrow 1 more book."; break; case int i when i == 5: _loansMessage = "You currently have " + userLoansTotal + " loans. This is the maximum number of loans."; break; } // get the books referenced by the loans if any var bookLoans = _bookRepository.GetUsersLoanedBooks(userLoans, userId); // get all available books not existing in the loan table List <Book> availableBooks = _bookRepository.GetAvailableBooks().ToList(); var borrowListViewModel = new BorrowListViewModel() { AvailableBooks = availableBooks.ToList(), UserLoanedBooks = bookLoans.ToList(), UserId = _userManager.GetUserId(User), LoanMessage = _loansMessage }; return(View(borrowListViewModel)); }
public ActionResult SearchBorrow(String SearchKey, Boolean haveFinish) { BorrowBusinessLayer bbl = new BorrowBusinessLayer(); BorrowListViewModel bvml = new BorrowListViewModel(); List <Borrow> b = bbl.SearchBorrowList(SearchKey, haveFinish); bvml.borrows = BorrowSealed(b); if (haveFinish) { return(View("HaveFinish", bvml)); } else { return(View("Borrow", bvml)); } }
public ActionResult ReturnBorrows(BorrowListViewModel model) { borrowService.ReturnBooks(model.BorrowsId); return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); }
public IActionResult BorrowList(string bookIdent) { string userId = _userManager.GetUserId(User); List <Loan> allUserLoans = _loanRepository.GetCurrentLoansByUserId(userId).ToList(); var userLoansTotal = allUserLoans.Count(); var loanAdded = false; // add the new loan to the DB if the user doesn't have five books out on loan if (userLoansTotal < 5) { loanAdded = _loanRepository.AddNewLoan(bookIdent, userId); } // update loan data following the addition of a new loan to the loan table allUserLoans.Clear(); allUserLoans = _loanRepository.GetCurrentLoansByUserId(userId).ToList(); userLoansTotal = allUserLoans.Count(); if ((userLoansTotal != 5) && (loanAdded == false)) { userLoansTotal = 100; } // prepare a message for the user advising them of their loan status var loansLeft = (5 - userLoansTotal); switch (userLoansTotal) { case int i when i == 0: _loansMessage = "You currently have " + userLoansTotal + " loan. You may borrow up to " + loansLeft + " books."; break; case int i when i == 1: _loansMessage = "You currently have " + userLoansTotal + " loan. You may borrow another " + loansLeft + " books."; break; case int i when i > 1 && i <= 3: _loansMessage = "You currently have " + userLoansTotal + " loans. You may borrow another " + loansLeft + " books."; break; case int i when i == 4: _loansMessage = "You currently have " + userLoansTotal + " loans. You may borrow 1 more book."; break; case int i when i == 5: _loansMessage = "You currently have " + userLoansTotal + " loans. This is the maximum number of loans."; break; case int i when i == 6: _loansMessage = "You currently have 5 loans. This is the maximum number of loans."; break; case int i when i == 100: _loansMessage = "Borrow Request Failed"; break; } // get the user's loaned books List <Book> bookLoans = null; if (userLoansTotal > 0) { bookLoans = _bookRepository.GetUsersLoanedBooks(allUserLoans, userId).ToList(); } // get all available books not existing in the loan table List <Book> availableBooks = _bookRepository.GetAvailableBooks().ToList(); bool tempTextColRed = true; if ((userLoansTotal >= 0) && (userLoansTotal < 5)) { tempTextColRed = false; } var borrowListViewModel = new BorrowListViewModel() { AvailableBooks = availableBooks, UserLoanedBooks = bookLoans, LoanBookCount = userLoansTotal, UserId = _userManager.GetUserId(User), LoanMessage = _loansMessage, TextColorRed = tempTextColRed }; return(View(borrowListViewModel)); }