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 })); } }