Exemple #1
0
        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)
                          .OrderBy(p => p.Id)
                          .Skip(currentPage * currentPageSize)
                          .Take(currentPageSize)
                          .ToList();

                _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);
        }
Exemple #2
0
        //
        // GET: /Photos/

        public ViewResult Index()
        {
            return(View(photoRepository.AllIncluding(photo => photo.Album)));
        }