Ejemplo n.º 1
0
 public Task AddPokemonAsync(BusinessLogic.Pokemon pokemon)
 {
     _context.Pokemon.Add(new Pokemon()
     {
         Name   = pokemon.Name,
         Height = pokemon.Height,
         Weight = pokemon.Weight
     });
     _context.SaveChangesAsync();
     return(Task.FromResult <object>(null));
 }
Ejemplo n.º 2
0
        // if types are included, they must have IDs
        public async Task AddPokemonAsync(BusinessLogic.Pokemon pokemon)
        {
            var entity = new Pokemon
            {
                Name             = pokemon.Name,
                Height           = pokemon.Height,
                Weight           = pokemon.Weight,
                PokemonTypeJoins = pokemon.Types.Select(t => new PokemonTypeJoin {
                    TypeId = t.Id
                }).ToList()
            };

            // if name is already in use....
            if (await _context.Pokemon.AnyAsync(p => p.Name == entity.Name))
            {
                throw new InvalidOperationException("Already exists");
            }

            _context.Add(entity);
            await _context.SaveChangesAsync();
        }