Example #1
0
        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());
        }