public ActionResult RenewLoan(string barcode, string personId = "") { if (Session["Borrower"] == null && Session["User"] == null) { return(RedirectToAction("Login")); } Borrower borrower = null; // Let's retrieve the borrower from the session if (Session["Borrower"] != null) { borrower = (Borrower)Session["Borrower"]; } // Otherwise, let's retrieve him/her from the database else { try { borrower = Borrower.getByPersonId(personId); } catch { return(View("Error500")); } } Category category; // Let's try to get the borrower's category to get the period of a loan try { category = Category.getById(borrower.CategoryId); } catch { return(View("Error500")); } // Let's try to renew the loan try { Borrow.renewLoan(barcode, category.Period); Session["RenewLoanSuccess"] = true; } catch { return(View("Error500")); } if (Session["Borrower"] != null) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Index", new { PersonId = borrower.PersonId })); } }
public ActionResult Index(string PersonId = "") { if (Session["Borrower"] == null && Session["User"] == null) { return(RedirectToAction("Login")); } Borrower borrower = null; // If the borrower is in session, let's retrieve it if (Session["Borrower"] != null) { borrower = (Borrower)Session["Borrower"]; } // If not, let's try to fetch it from database else { try { borrower = Borrower.getByPersonId(PersonId); } catch { return(View("Error500")); } } ViewBag.borrower = borrower; // Let's try to get all borrowed books by the borrower try { ViewBag.borrows = Borrow.getByPersonId(borrower.PersonId); } catch { return(View("Error500")); } return(View()); }