Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Web.Caching;
- using System.Web.Mvc;
- using StudentPortal.Repository;
- namespace StudentPortal.Controllers
- {
- public class HomeController : Controller
- {
- private BooksRepository _booksRepository = new BooksRepository();
- public ActionResult Index()
- {
- if (HttpContext.Cache["allBooks"] == null)
- {
- HttpContext.Cache.Insert("allBooks", _booksRepository.GetAll(), null,
- DateTime.Now.AddHours(1), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
- }
- IEnumerable<Book> allBooks = HttpContext.Cache["allBooks"] as IEnumerable<Book>;
- return View(allBooks);
- }
- public ActionResult About()
- {
- ViewBag.SessionValue = Session["test"] != null ? Session["test"].ToString() : "Session is empty";
- return View();
- }
- public ActionResult Contact()
- {
- ViewBag.Message = "Your contact page.";
- return View();
- }
- [Authorize]
- public ActionResult MyPage()
- {
- var currentUser = User.Identity.Name;
- Session["test"] = "Session contains data for user " + currentUser;
- ViewBag.UserName = currentUser;
- if (HttpContext.Cache[currentUser] == null)
- {
- HttpContext.Cache.Insert(currentUser, _booksRepository.GetBooksForUser(currentUser), null,
- DateTime.Now.AddHours(1), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
- }
- ViewBag.BooksRead = HttpContext.Cache[currentUser] as IEnumerable<Book>;
- return View();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement