public ActionResult Index()
        {
            ICasheProvider cashe = new DefaultCasheProvider();

            List <Category> categories;

            if (cashe.IsSet(Consts.CategoriesCasheKey))
            {
                categories = cashe.Get(Consts.CategoriesCasheKey) as List <Category>;
            }
            else
            {
                categories = db.Categories.ToList();
                cashe.Set(Consts.CategoriesCasheKey, categories, 60);
            }

            List <Book> latests;

            if (cashe.IsSet(Consts.LatestsCaheKey))
            {
                latests = cashe.Get(Consts.LatestsCaheKey) as List <Book>;
            }
            else
            {
                latests = db.Books.Where(a => !a.Hidden).OrderByDescending(a => a.DateAdded).Take(3).ToList();
                cashe.Set(Consts.LatestsCaheKey, latests, 60);
            }

            List <Book> bestsellers;

            if (cashe.IsSet(Consts.BestsellersCasheKey))
            {
                bestsellers = cashe.Get(Consts.BestsellersCasheKey) as List <Book>;
            }
            else
            {
                bestsellers = db.Books.Where(a => !a.Hidden && a.Bestseller).OrderBy(a => Guid.NewGuid()).Take(3).ToList();
                cashe.Set(Consts.BestsellersCasheKey, bestsellers, 60);
            }



            var vm = new HomeViewModel()
            {
                Cagegories  = categories,
                Latests     = latests,
                Bestsellers = bestsellers
            };


            return(View(vm));
        }
示例#2
0
        // GET: Home
        public ActionResult Index()
        {
            List <Album> newArrivals;

            ICasheProvider casheProvider = new DefaultCasheProvider();

            if (casheProvider.IsSet(Const.NewItemCasheKey))
            {
                newArrivals = casheProvider.Get(Const.NewItemCasheKey) as List <Album>;
            }
            else
            {
                newArrivals = db.Albums.Where(w => !w.IsHidden).OrderByDescending(o => o.DateAdded).Take(3).ToList();
                casheProvider.Set(Const.NewItemCasheKey, newArrivals, 30);
            }


            var genres = db.Genres.ToList();

            var bestSellers = db.Albums.Where(w => !w.IsHidden && w.IsBestseller).OrderBy(g => Guid.NewGuid()).Take(3).ToList();

            var vm = new HomeViewModel
            {
                Bestsellers = bestSellers,
                NewArrivals = newArrivals,
                Genres      = genres
            };

            return(View(vm));
        }