// GET: Admin/Albums public async Task <ActionResult> Index(int?page, string keyword) { var vm = new AlbumListVM() { Keyword = keyword, PageIndex = page ?? 1, PageSize = SettingsManager.Album.PageSize }; var query = _db.Albums.AsNoTracking().AsQueryable(); if (!string.IsNullOrEmpty(keyword)) { query = query.Where(d => d.Title.Contains(keyword)); } var list = await query.OrderByDescending(d => d.Importance) .Skip((vm.PageIndex - 1) * vm.PageSize).Take(vm.PageSize).ProjectTo <AlbumVM>().ToListAsync(); //_categoryServices.GetPagedElements(vm.PageIndex-1, vm.PageSize, vm.Keyword, out totalCount); vm.TotalCount = await query.CountAsync(); vm.Albums = new StaticPagedList <AlbumVM>(list, vm.PageIndex, vm.PageSize, vm.TotalCount); ViewBag.PageSizes = new SelectList(Site.PageSizes()); return(View(vm)); }
public ActionResult Albums() { AlbumListVM viewModel = new AlbumListVM(); var albums = (IList <Album>)_albumRepository.GetAll(); viewModel.AllAlbums = Mapper.Map <IList <AlbumVM> >(albums); foreach (var album in viewModel.AllAlbums) { album.PathAlbum = album.Path + album.Guid + '/'; } return(View(viewModel)); }