private static void AddNewPokemon(DbContextOptions <PokemonDBContext> options) { using (var dbContext = new PokemonDBContext(options)) { if (!dbContext.Pokemon.Any(x => x.Name == "Charmander")) { var newPokemon = new Pokemon { Name = "Charmander", Height = 36, Type = new Type { Name = "Fire" } }; dbContext.Pokemon.Add(newPokemon); dbContext.SaveChanges(); } else { Pokemon p = dbContext.Pokemon.First(x => x.Name == "charmander"); Console.WriteLine($"You already have a {p.Name}....dont be greedy"); } } }
private static void DisplayPokemon(DbContextOptions <PokemonDBContext> options) { using (var dbContext = new PokemonDBContext(options)) { if (!dbContext.Pokemon.Any()) { Console.WriteLine("No Pokemon Found... GO Catch Some"); } else { foreach (Pokemon p in dbContext.Pokemon.Include(x => x.Type)) { var str = $"{p.PokemonId}:{p.Name} ({p.Height})"; if (p.Evolution != null) { str += $"[{p.Evolution}]"; } //foreach( Type type in dbContext.Type) //{ // if(p.TypeId == type.TypeId) // str += $"[{type.Name}]"; //} str += $"[{p.Type.Name}]"; Console.WriteLine(str); } } } }
public PokemonTranslatorService() { pokeService = new PokeAPIService(); shakeService = new ShakespeareService(); pokemonDBContext = new PokemonDBContext(); pokeRepository = new GenericRepository <PokemonEntity, string> (pokemonDBContext); }
private static void DeleteSomePokemon(DbContextOptions <PokemonDBContext> options) { using (var dbContext = new PokemonDBContext(options)) { if (dbContext.Pokemon.FirstOrDefault(x => x.Name == "Charmander") is Pokemon charmander) { } } }
public PokemonTranslatorService(PokeAPIService _pokeService, ShakespeareService _shakeService, PokemonDBContext _pokemonDBContext, GenericRepository <PokemonEntity, string> _pokeRepository ) { pokeService = _pokeService; shakeService = _shakeService; pokemonDBContext = _pokemonDBContext; pokeRepository = _pokeRepository; }
private static void EditSomePokemon(DbContextOptions <PokemonDBContext> options) { // in between dbContext creation and each savechnages call is a transactoon using (var dbContext = new PokemonDBContext(options)) { //ef "tracks the" object you pull out of it Pokemon charmander = dbContext.Pokemon.Include(x => x.Type) .First(x => x.Name == "charmander"); var grass = dbContext.Type.First(x => x.Name == "Grass"); var fire = dbContext.Type.First(x => x.Name == "Fire"); if (charmander.Type == fire) { } } }
public PokemonsService(PokemonDBContext context, IMapper mapper) { _context = context; _context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; _mapper = mapper; }
public GenerationService(PokemonDBContext context, IMapper mapper) { _context = context; _mapper = mapper; }