public async Task <ViewModel> GetViewModelAsync(string id)
        {
            var viewModel = new ViewModel();

            var entity = await _repository.GetAsync(id).ConfigureAwait(false);

            if (entity != null)
            {
                viewModel.Entity = new ViewModelEntity()
                {
                    Id             = entity.Id,
                    Abilities      = entity.Abilities,
                    Attack         = entity.Attack,
                    CaptureRate    = entity.CaptureRate,
                    Category       = entity.Category,
                    Defense        = entity.Defense,
                    EggSteps       = entity.EggSteps,
                    ExpGroup       = entity.ExpGroup,
                    Height         = entity.Height,
                    HitPoints      = entity.HitPoints,
                    Name           = entity.Name,
                    PictureUrl     = $"https://assets.pokemon.com/assets/cms2/img/pokedex/full/{id}.png",
                    SpecialAttack  = entity.SpecialAttack,
                    SpecialDefense = entity.SpecialDefense,
                    Speed          = entity.Speed,
                    Type1          = entity.Type1,
                    Type2          = entity.Type2,
                    Weight         = entity.Weight
                };
            }

            return(viewModel);
        }
        public async Task <ActionResult <Pokemon> > GetAsync(string id)
        {
            var entity = default(Pokemon);

            try
            {
                entity = await _repository.GetAsync(id).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                var baseMsg = $"Error retrieving Pokemon \"{id}\".";
                _logger.LogError(ex, $"{baseMsg} Check the log for details.");
            }

            if (entity == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(entity));
            }
        }
Example #3
0
 public async Task <Pokemon> GetAsync(string name)
 {
     return(await _repository.GetAsync(name.ToLowerInvariant()));
 }