Ejemplo n.º 1
0
        public async Task OnGet(PokemonIndexVM pokemonIndex, int?pageIndex)
        {
            PokemonIndex = _pokemonVMService.GetPokemonsVM(pageIndex ?? 0, ITEMS_PER_PAGE, pokemonIndex.TypesFilterApplied);

            string userId = _userManager.FindByNameAsync(User.Identity.Name).Result.Id;


            TrainerPokedex = _db.PokeDex
                             .Include(pp => pp.PokedexPokemons)
                             .ThenInclude(p => p.Pokemon)
                             .Where(pp => pp.TrainerId == userId)
                             .FirstOrDefault();
        }
Ejemplo n.º 2
0
        public PokemonIndexVM GetPokemonsVM(int pageIndex, int itemsPerPage, string typeName)
        {
            IQueryable <Pokemon> pokemons = _pokemonRepo.GetAll().OrderBy(Pokemon => Pokemon.PokeNumber);

            if (typeName != null && typeName != "NULL")
            {
                pokemons = pokemons.Where(p => p.Type0 == typeName || p.Type1 == typeName);
            }

            int totalItems = pokemons.Count();

            pokemons = pokemons.Skip(pageIndex * itemsPerPage).Take(itemsPerPage);

            var vm = new PokemonIndexVM()
            {
                Pokemons = pokemons.Select(p => new PokemonVM
                {
                    Id         = p.Id,
                    PokeNumber = p.PokeNumber,
                    Name       = p.Name,
                    Type0      = p.Type0,
                    Type1      = p.Type1,
                    Attack     = p.Attack,
                    Defense    = p.Defense,
                    Speed      = p.Speed,
                }).ToList(),
                Types = GetTypes().ToList(),

                PaginationInfo = new PaginationInfoVM()
                {
                    PageIndex    = pageIndex,
                    ItemsPerPage = pokemons.Count(),
                    TotalItems   = totalItems,
                    TotalPages   = int.Parse(Math.Ceiling(((decimal)totalItems / itemsPerPage)).ToString())
                }
            };

            vm.PaginationInfo.Next     = (vm.PaginationInfo.PageIndex == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
            vm.PaginationInfo.Previous = (vm.PaginationInfo.PageIndex == 0) ? "is-disabled" : "";
            return(vm);
        }