Exemplo n.º 1
0
        public ActionResult All(string id)
        {
            int page;
            if (id == string.Empty || id == null)
            {
                page = 1;
            }
            else
            {
                page = this.identifier.DecodeId(id);
            }

            var allItemsCount = this.places.GetAll().Count();
            var totalPages = (int) Math.Ceiling(allItemsCount / (decimal) ItemsPerPage);
            var itemsToSkip = (page - 1) * ItemsPerPage;
            var placesForVisualizing = this.places.GetAll()
                .OrderBy(x => x.Name)
                .Skip(itemsToSkip)
                .Take(ItemsPerPage)
                .ToList();
            var placesViewModel = this.Mapper.Map<ICollection<PlaceResponseViewModel>>(placesForVisualizing);

            var viewModel = new PlacesResponseViewModel(this.identifier)
            {
                CurrentPage = page,
                TotalPages = totalPages,
                Places = placesViewModel
            };

            return this.View(viewModel);
        }
Exemplo n.º 2
0
        public ActionResult All(string id)
        {
            int page;

            if (id == string.Empty || id == null)
            {
                page = 1;
            }
            else
            {
                page = this.identifier.DecodeId(id);
            }

            var allItemsCount        = this.places.GetAll().Count();
            var totalPages           = (int)Math.Ceiling(allItemsCount / (decimal)ItemsPerPage);
            var itemsToSkip          = (page - 1) * ItemsPerPage;
            var placesForVisualizing = this.places.GetAll()
                                       .OrderBy(x => x.Name)
                                       .Skip(itemsToSkip)
                                       .Take(ItemsPerPage)
                                       .ToList();
            var placesViewModel = this.Mapper.Map <ICollection <PlaceResponseViewModel> >(placesForVisualizing);

            var viewModel = new PlacesResponseViewModel(this.identifier)
            {
                CurrentPage = page,
                TotalPages  = totalPages,
                Places      = placesViewModel
            };

            return(this.View(viewModel));
        }