public ActionResult Illustration() { imageRepository = new ImageRepository(); albumRepository = new AlbumRepository(); return View(albumRepository.AllIncluding(m => m.Images).OrderBy(m => m.OrderNumber)); }
public async Task <IActionResult> Get(int?page, int?pageSize) { PaginationSet <AlbumViewModel> pagedSet = new PaginationSet <AlbumViewModel>(); try { if (await _authorizationService.AuthorizeAsync(User, "AdminOnly")) { int currentPage = page.Value; int currentPageSize = pageSize.Value; List <Album> _albums = null; //记录Album的总数量 int _totalAlbums = new int(); _albums = _albumRepository .AllIncluding(t => t.Photos) .OrderBy(t => t.Id) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); _totalAlbums = _albumRepository.GetAll().Count(); //转换成ViewModel IEnumerable <AlbumViewModel> _albumsVM = Mapper.Map <IEnumerable <Album>, IEnumerable <AlbumViewModel> >(_albums); //转换成分页 pagedSet = new PaginationSet <AlbumViewModel>() { Page = currentPage, TotalCount = _totalAlbums, TotalPages = (int)Math.Ceiling((decimal)_totalAlbums / currentPageSize), Items = _albumsVM }; } else { CodeResultStatus _codeResult = new CodeResultStatus(401); return(new ObjectResult(_codeResult)); } } catch (Exception ex) { _loggingRepository.Add(new Error() { Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now }); _loggingRepository.Commit(); } return(new ObjectResult(pagedSet)); }
public async Task <IActionResult> Get(int?page, int?pageSize) { PaginationSet <AlbumViewModel> pagedSet = new PaginationSet <AlbumViewModel>(); try { if (await _authorizationService.AuthorizeAsync(User, "AdminOnly")) { int currentPage = page.Value; int currentPageSize = pageSize.Value; List <Album> _albums = null; int _totalAlbums = new int(); var username = Request.Cookies["user"]; User user = _userRepository.GetSingleByUsername(username); int user_id = user.Id; _albums = _albumRepository .AllIncluding(a => a.Photos) .OrderBy(a => a.Id) .Where(s => s.User_ID == user_id) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); _totalAlbums = _albumRepository.GetAll().Count(); IEnumerable <AlbumViewModel> _albumsVM = Mapper.Map <IEnumerable <Album>, IEnumerable <AlbumViewModel> >(_albums); pagedSet = new PaginationSet <AlbumViewModel>() { Page = currentPage, TotalCount = _totalAlbums, TotalPages = (int)Math.Ceiling((decimal)_totalAlbums / currentPageSize), Items = _albumsVM }; } else { CodeResultStatus _codeResult = new CodeResultStatus(401); return(new ObjectResult(_codeResult)); } } catch (Exception ex) { _loggingRepository.Add(new Error() { Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now }); _loggingRepository.Commit(); } return(new ObjectResult(pagedSet)); }
public PaginationSet <PhotoViewModel> Get(int?page, int?pageSize) { PaginationSet <PhotoViewModel> pagedSet = null; try { int currentPage = page.Value; int currentPageSize = pageSize.Value; List <Photo> _photos = null; int _totalPhotos = new int(); _photos = _photoRepository .AllIncluding(p => p.Album) .OrderByDescending(p => p.Rating) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); var albums = _albumRepository.AllIncluding(a => a.User).ToList(); foreach (var photo in _photos) { photo.Album.User = albums.FirstOrDefault(a => a.Id == photo.AlbumId).User; } _totalPhotos = _photoRepository.GetAll().Count(); IEnumerable <PhotoViewModel> _photosVM = Mapper.Map <IEnumerable <Photo>, IEnumerable <PhotoViewModel> >(_photos); pagedSet = new PaginationSet <PhotoViewModel>() { Page = currentPage, TotalCount = _totalPhotos, TotalPages = (int)Math.Ceiling((decimal)_totalPhotos / currentPageSize), Items = _photosVM }; } catch (Exception ex) { _loggingRepository.Add(new Error() { Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now }); _loggingRepository.Commit(); } return(pagedSet); }
public async Task <IActionResult> Get(int?page, int?pageSize) { PaginationSet <AlbumViewModel> pagedSet = new PaginationSet <AlbumViewModel>(); try { int currentPage = page.Value; int currentPageSize = pageSize.Value; List <Album> _albums = null; int _totalAlbums = new int(); _albums = _albumRepository .AllIncluding(a => a.Photos) .OrderBy(a => a.Id) .Skip(currentPage * currentPageSize) .Take(currentPageSize) .ToList(); _totalAlbums = _albumRepository.GetAll().Count(); IEnumerable <AlbumViewModel> _albumsVM = Mapper.Map <IEnumerable <Album>, IEnumerable <AlbumViewModel> >(_albums); pagedSet = new PaginationSet <AlbumViewModel>() { Page = currentPage, TotalCount = _totalAlbums, TotalPages = (int)Math.Ceiling((decimal)_totalAlbums / currentPageSize), Items = _albumsVM }; } catch (Exception ex) { _loggingRepository.Add(new Error() { Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now }); _loggingRepository.Commit(); } return(new ObjectResult(pagedSet)); }
// // GET: /Album/ public ViewResult Index() { return(View(albumRepository.AllIncluding(album => album.Genre))); }