示例#1
0
        private static IQueryable<Pokemon> BaseQuery(PokemonStore.DAL.PokemonContext context)
        {
            var query = from p in context.Pokemons

                        select new  Pokemon {
                            ID = p.ID,
                            Name = p.Name,
                            Type = p.Type
                        };
            return query;
        }
        public async Task <ImportingStatus> ImportPokemon(string filePath)
        {
            try
            {
                Console.WriteLine($"Received pokemon to import: {filePath}...");

                var fileContent = File.ReadAllText(filePath);
                var reader      = new PokemonReader();
                var pokemon     = reader.ReadPokemon(fileContent);

                var database = new PokemonStore();
                await database.SavePokemon(pokemon);

                Console.WriteLine($"Pokemon saved. Id: {pokemon.Id}, Name: {pokemon.Name}, Type: {pokemon.Type}, Timestamp: {pokemon.Timestamp}");

                return(ImportingStatus.Success);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error! " + e.Message);
                return(ImportingStatus.Error);
            }
        }
        public async Task <ImportingStatus> ImportPokemon(string filePath)
        {
            try
            {
                Console.WriteLine($"Received pokemon to import: {filePath}..."); // usage of static method

                var     fileContent = File.ReadAllText(filePath);
                Pokemon pokemon     = JsonConvert.DeserializeObject <Pokemon>(fileContent); // usage of framework method
                pokemon.Timestamp = DateTime.Now;

                var database = new PokemonStore(); // new keyword
                await database.SavePokemon(pokemon);

                Console.WriteLine($"Pokemon saved. Id: {pokemon.Id}, Name: {pokemon.Name}, Type: {pokemon.Type}, Timestamp: {pokemon.Timestamp}");

                return(ImportingStatus.Success);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error! " + e.Message);
                return(ImportingStatus.Error);
            }
        }