Ejemplo n.º 1
0
 public PokemonModel(PokemonDataModel model)
 {
     Id         = model.Id;
     Name       = model.Name;
     ImageId    = model.ImageId;
     Difficulty = new DifficultyModel(model.Difficulty);
 }
Ejemplo n.º 2
0
        public PokemonModel Save(PokemonDOM pokemonModel)
        {
            var difficulty = difficultyRepository.GetByLevel(pokemonModel.DifficultyLevel);
            var pokemon    = new PokemonDataModel {
                Name = pokemonModel.Name, ImageId = pokemonModel.ImageId, Difficulty = difficulty
            };

            difficulty.Pokemons.Add(pokemon);

            return(new PokemonModel(pokemonRepository.Save(pokemon)));
        }
Ejemplo n.º 3
0
 public PokemonDataModel Save(PokemonDataModel pokemonModel)
 {
     using (var session = helper.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.Save(pokemonModel);
             session.Transaction.Commit();
             return(pokemonModel);
         }
     }
 }
Ejemplo n.º 4
0
        public PokemonSearchWindowViewModel()
        {
            // 入力補完候補を設定
            PokemonDataModel pokemonDataModel = new PokemonDataModel();

            Pokemons = pokemonDataModel.GetPokemons();

            // 紐づけ
            PokemonImage = PokemonSearchWindowModel
                           .ObserveProperty(m => m.PokemonId)
                           .Select(x => ImageFactoryModel.CreatePokemonImage(x)).ToReactiveProperty();

            // 処理
            PokemonName.Subscribe(pokemonName => PokemonSearchWindowModel.ChangePokemonId(pokemonName));

            // コマンド
            CloseWindowCommand = new DelegateCommand <object>(CloseWindow);
        }
        public async Task <ActionResult <List <PokemonDataModel> > > GetPokemonList(int pageIndex)
        {
            List <PokemonDataModel> cacheValue;

            if (!_cache.TryGetValue <List <PokemonDataModel> >(pageIndex, out cacheValue))
            {
                //Get Data if not in cache.

                //Create List to store Pokemon Data.
                List <PokemonDataModel> pokemonList = new List <PokemonDataModel>();

                //Data Settings per page.
                int limit  = 20;
                int offset = 20 * pageIndex;

                if (pageIndex > 50 || pageIndex < 0)
                {
                    return(BadRequest());
                }

                //Get Page Data.
                var pokemonPageData = await pokeClient.GetNamedResourcePageAsync <Pokemon>(limit, offset);

                if (pokemonPageData == null)
                {
                    return(NotFound());
                }

                //Processing for each one of the pokemon in the page data retrieved.
                foreach (var result in pokemonPageData.Results)
                {
                    //Create Data Structures for one pokemon.
                    PokemonDataModel pokemonModel = new PokemonDataModel
                    {
                        Types     = new List <string>(),
                        Abilities = new List <string>()
                    };

                    // Get Opertiaon to obtain the specific pokemon data.
                    var fetchedPokemonData = await pokeClient.GetResourceAsync <Pokemon>(result.Name);

                    if (fetchedPokemonData == null)
                    {
                        return(NotFound());
                    }
                    //Fill the Data Model
                    pokemonModel.Name     = fetchedPokemonData.Name;
                    pokemonModel.Weight   = fetchedPokemonData.Weight;
                    pokemonModel.ImageUrl = fetchedPokemonData.Sprites.FrontDefault;
                    pokemonModel.Types.AddRange(fetchedPokemonData.Types.Select(element => element.Type.Name));
                    pokemonModel.Abilities.AddRange(fetchedPokemonData.Abilities.Select(element => element.Ability.Name));

                    //Add the pokemon data to the list.
                    pokemonList.Add(pokemonModel);
                }
                cacheValue = pokemonList;

                //Cache expiration in 3 minutes
                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        .SetSlidingExpiration(TimeSpan.FromMinutes(3));

                // Save values in cache for a given key.
                _cache.Set <List <PokemonDataModel> >(pageIndex, cacheValue, cacheEntryOptions);
            }
            return(Ok(cacheValue));
        }