public static void InsertMultiplePokemons() { var pokemon1 = new Pokemon { Name = "Eevee", Legendary = false, SessionId = 1 }; var pokemon2 = new Pokemon { Name = "Onix", Legendary = false, SessionId = 1 }; using (var context = new PokemonContext()) { context.Database.Log = Console.WriteLine; context.Pokemons.AddRange(new List <Pokemon> { pokemon1, pokemon2 }); context.SaveChanges(); } }
public static ApplicationUserManager Create(IdentityFactoryOptions <ApplicationUserManager> options, IOwinContext context) { PokemonContext db = context.Get <PokemonContext>(); ApplicationUserManager manager = new ApplicationUserManager(new UserStore <User>(db)); return(manager); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.EnvironmentName == "Development") { app.UseDeveloperExceptionPage(); } app.UseStatusCodePagesWithReExecute("/api/error"); app.UseExceptionHandler("/api/error"); app.UseMvc(); var opts = new DbContextOptionsBuilder <PokemonContext>() .UseSqlite(_inMemorySqlite) .Options; //TODO: Move to service class. Error handling, logging. var path = Path.Combine(env.WebRootPath, "pokemon"); var files = Directory.GetFiles(path); using (var context = new PokemonContext(opts)) { // Create the schema in the database var mapper = GetMapper(); context.Database.EnsureCreated(); foreach (var file in files) { var jsonString = File.ReadAllText(file); var pokemonDto = JsonConvert.DeserializeObject <PokemonDto>(jsonString); var pokemon = mapper.Map(pokemonDto, new Core.Entities.Pokemon()); context.Pokemon.Add(mapper.Map(pokemonDto, pokemon)); } context.SaveChanges(); } }
public PokemonQuery(IPokemonRepository pokemonRepository) { Field <ListGraphType <PokemonType> >( "AllPokemons", resolve: context => pokemonRepository.GetPokemons() ); Field <PokemonType>( "PokemonById", arguments: new QueryArguments(new QueryArgument <IntGraphType> { Name = "id" }), resolve: context => pokemonRepository.GetPokemonById((context.GetArgument <int>("id"))) ); Field <PaginationType>( "PokemonPagination", arguments: new QueryArguments( new QueryArgument <IntGraphType> { Name = "first", DefaultValue = 0 }, new QueryArgument <IntGraphType> { Name = "after", DefaultValue = 0 }, new QueryArgument <IntGraphType> { Name = "countPerPage", DefaultValue = 0 }, new QueryArgument <IntGraphType> { Name = "currentPage", DefaultValue = 0 }, new QueryArgument <StringGraphType> { Name = "sortBy" } ), resolve: context => { int totalCount; int totalPage; var temp = context.GetArgument <int>("countPerPage"); using (var ctx = new PokemonContext()) { totalCount = ctx.PokemonData.Count(); if (context.GetArgument <int>("countPerPage") != 0 && context.GetArgument <int>("first") != 0) { totalPage = (int)Math.Ceiling((double)context.GetArgument <int>("first") / temp); } else if (context.GetArgument <int>("countPerPage") != 0) { totalPage = (int)Math.Ceiling((double)ctx.PokemonData.Count() / temp); } else { totalPage = 0; } } return(new Pagination(totalCount, context.GetArgument <int>("first"), context.GetArgument <int>("after"), context.GetArgument <int>("countPerPage"), context.GetArgument <int>("currentPage"), totalPage, context.GetArgument <string>("sortBy"))); } ); }
/// <summary> /// Deletes the specified pokemon. /// </summary> /// <returns>The deleted Pokemon</returns> public async Task <Pokemon> RemovePokemon([Service] PokemonContext pokemonContext, int id) { var pokemon = pokemonContext.Pokemon.Find(id); pokemonContext.Pokemon.Remove(pokemon); await pokemonContext.SaveChangesAsync(); return(pokemon); }
public static void ProjectionQuery() { using (var contex = new PokemonContext()) { contex.Database.Log = Console.WriteLine; var pokemon = contex.Pokemons .Select(n => new { n.Name, n.Legendary }) .ToList(); } }
public PokemonClient(IConfiguration configuration, PokemonContext pokemonContext) { _context = pokemonContext; PokemonApiUrl = configuration["PokemonAPI"]; _httpClient = new HttpClient { BaseAddress = new Uri(PokemonApiUrl) }; _httpClient.DefaultRequestHeaders.Accept.Clear(); _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, PokemonContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseGraphiQl(); app.UseMvc(); context.Database.Migrate(); }
/// <summary> /// Updates the pokemon with the specified id /// </summary> /// <param name="pokemonContext">The pokemon DB context.</param> /// <returns>All pokemon from the context.</returns> public async Task <Pokemon> UpdatePokemon([Service] PokemonContext pokemonContext, int id, string name, string type) { var pokemon = pokemonContext.Pokemon.Find(id); pokemon.name = name; pokemon.type = type; await pokemonContext.SaveChangesAsync(); pokemon = pokemonContext.Pokemon.Find(id);//retrieve the newly created pokemon return(pokemon); }
public static void SimplePokemonQueries() { using (var contex = new PokemonContext()) { var pokemons = contex.Pokemons. Where(n => n.Name == "Eevee") .OrderBy(n => n.Name); foreach (var pokemon in pokemons) { Console.WriteLine(pokemon.Name); } } }
public static void InsertSession() { var session = new Session { SessionName = SessionNameEnum.Hoenn }; using (var context = new PokemonContext()) { context.Database.Log = Console.WriteLine; context.Sessions.Add(session); context.SaveChanges(); } }
/// <summary> /// Adds a new pokemon. /// </summary> /// <returns>A newly created pokemon.</returns> public async Task <Pokemon> Pokemon([Service] PokemonContext pokemonContext, string name, string type) { var pokemon = new Pokemon() { id = pokemonContext.Pokemon.Select(p => p.id).Max() + 1, name = name, type = type }; pokemonContext.Pokemon.Add(pokemon); await pokemonContext.SaveChangesAsync(); return(pokemon); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, PokemonContext pokeContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors(builder => builder .WithOrigins("http://localhost") .AllowAnyHeader()); app.UseMvc(); PokeDBInitializer.Initialize(pokeContext); }
public static void SimplePokemonGraphQuery() { using (var contex = new PokemonContext()) { /* * var pokemons = contex.Pokemons.Include(n => n.Sessions); */ var pokemon = contex.Pokemons .FirstOrDefault(n => n.Name.StartsWith("Eevee")); /* * context.Entry(pokemon).Collection(n => n.Sessions.Count()); */ } }
public static void InsertPokemon(string name, bool legendary, string types) { var pokemon = new Pokemon { Name = name, Legendary = legendary, TypeString = types }; using (var context = new PokemonContext()) { context.Database.Log = Console.WriteLine; context.Pokemons.Add(pokemon); context.SaveChanges(); } }
public PaginationQuery(IPokemonRepository pokemonRepository) { Field<PaginationType>( "PokemonPagination", arguments: new QueryArguments(new QueryArgument<IntGraphType> { Name = "first" }), new QueryArguments(new QueryArgument<IntGraphType> { Name = "last" }), resolve: context => { int totalCount; using (var ctx = new PokemonContext()) { totalCount = ctx.PokemonData.Count(); } return new Pagination(totalCount, context.GetArgument<int>("first"), context.GetArgument<int>("last")); } ); }
private static async Task <Pokedata> CreatePokemon(Task <string> fromUrl) { Pokedata pokeTask = await fromUrl.ContinueWith(s => { PokemonContext db = new PokemonContext(); JToken p = JToken.Parse(s.Result); Pokedata poke = new Pokedata { PokemonId = (int)p["id"], DefaultImage = (string)p["sprites"]["front_default"], Name = (string)p["name"], Height = (int)p["height"], Weight = (int)p["weight"], /* * Moves = new JArray(p["moves"].Children()).Select(m => new Move // May want to collect this from DBSet directly to collect existing entity. May cause duplication. * { * MoveId = Utility.URLIndex((string)m["move"]["url"], true), * Name = (string)m["move"]["name"] * }).ToList(), * * Abilities = new JArray(p["abilities"].Children()).Select(a => new Ability * { * AbilityId = Utility.URLIndex((string)a["ability"]["url"], true), * Name = (string)a["ability"]["name"] * }).ToList(), */ Moves = new JArray(p["moves"].Children()).Select(m => (Move)DBAttribute(db.Moves, m["move"]) ).ToList(), Abilities = new JArray(p["abilities"].Children()).Select(a => (Ability)DBAttribute(db.Abilities, a["ability"]) ).ToList(), }; db.Dispose(); return(poke); }, TaskScheduler.Default); return(pokeTask); }
private PokemonContext AddTypesToPokemon(PokemonContext context) { foreach (var pokemon in context.Pokemon) { IQueryable <PokemonType> pokemonTypesQuery = from pokeType in context.PokemonType where pokeType.PokemonId == pokemon.Id select pokeType; List <PokemonType> pokemonTypes = pokemonTypesQuery.ToList(); foreach (PokemonType pokemonType in pokemonTypes) { pokemonType.Type = (from type in context.Type where type.Id == pokemonType.TypeId select type).Single(); if (null == pokemon.Types) { pokemon.Types = new List <Models.Type>(); } pokemon.Types.Add(pokemonType.Type); } } return(context); }
public ExploreController(PokemonContext context) { pokemonContext = context; random = new Random(); }
public HomeController(ILogger <HomeController> logger, PokemonContext context) { _logger = logger; _context = context; }
public PokemonController(PokemonContext context, IHostingEnvironment hostEnvironment) { _context = context; _hostEnvironment = hostEnvironment; }
public HomeController(PokemonContext pokemonContext) { _context = pokemonContext; }
public AccountController(PokemonContext context) { pokemonContext = context; }
public PokemonRepository(PokemonContext pokemonContext) { this.pokemonContext = pokemonContext; }
public HomeController(PokemonContext context, UserContext userContext, ILogger <HomeController> logger) { _pokemonContext = AddTypesToPokemon(context); _userContext = userContext; _logger = logger; }
public PokemonController(PokemonContext c) { _context = c; }
public UserRepository(PokemonContext context) { this.context = context; }
public EntrenadorController(PokemonContext c) { _context = c; }
public ChatListViewComponent(PokemonContext context) { _pokemonContext = context; }
public PokemonController(PokemonContext context) { _context = context; }