public GameQuery(GamesDbContext db) { var queryArguments = new QueryArgument[] { new QueryArgument <IdGraphType> { Name = "id" }, new QueryArgument <StringGraphType> { Name = "score" }, new QueryArgument <StringGraphType> { Name = "team1" }, new QueryArgument <StringGraphType> { Name = "team2" } }; Field <GameType>( "Game", arguments: new QueryArguments(queryArguments), resolve: context => { Game game = db .Games .FirstOrDefault(GetGamesFilter(context)); return(game); }); Field <ListGraphType <GameType> >( "Games", arguments: new QueryArguments(queryArguments), resolve: context => { var authors = db.Games; return(authors.Where(GetGamesFilter(context))); }); }
public GameSessionManager(IHubContext <GamesHub> hubContext, GamesDbContext context, GamesHistoryService historyService) { _hubContext = hubContext; _context = context; _historyService = historyService; }
public TransactionBehavior(IDbContextManager contextManager, GamesDbContext context) { _contextManager = contextManager; Context = context; _contextManager.RegisterContext(Context); }
public GamesDbContextCleaner(GamesDbContext context, IWebHostEnvironment environment, ILogger <GamesDbContextCleaner> logger) : base( context, environment, logger) { Credentials = context.Set <Credential>(); }
public async System.Threading.Tasks.Task DeletePlayerTestAsync() { DbContextOptions <GamesDbContext> options = new DbContextOptionsBuilder <GamesDbContext>().UseInMemoryDatabase("DeletePlayer").Options; using (GamesDbContext context = new GamesDbContext(options)) { Player newPlayer = new Player() { ID = "1", RoomID = "1", Name = "Farkus", Score = 500, Toad = true }; context.Add(newPlayer); await context.SaveChangesAsync(); Player foundPlayer = await context.Players.FirstOrDefaultAsync(player => player.ID == "1"); foundPlayer.Score = 250; context.Remove(foundPlayer); await context.SaveChangesAsync(); Player deletedPlayer = await context.Players.FirstOrDefaultAsync(player => player.ID == "1"); Assert.True(deletedPlayer == null); } }
private static void SeedFriends(GamesDbContext context, List <Friend> friends) { if (!context.Friends.Any()) { context.AddRange(friends); context.SaveChanges(); } }
private static void SeedGames(GamesDbContext context, List <Game> games) { if (!context.Games.Any()) { context.AddRange(games); context.SaveChanges(); } }
//Método constructor public App() { InitializeComponent(); using (GamesDbContext dbContext = new GamesDbContext()) { dbContext.Database.Migrate(); } }
public dynamic GetBestScores(int gameId) { using (var dbContext = new GamesDbContext()) { return(dbContext.Score.Include("User").Where(x => x.GameId == gameId).OrderBy(x => x.ScorePoint).Select(x => new { x.ScorePoint, x.User.Name }).Take(15).ToList()); } }
public async Task <IHttpActionResult> GetBestScores() { using (var dbContext = new GamesDbContext()) { return(Ok(await dbContext.Score.Include("User").Where(x => x.GameId == 1).OrderBy(x => x.ScorePoint).Select(x => new { x.ScorePoint, x.User.Name, x.User.Password }).Take(15).ToListAsync())); } }
private void ListarGames() { GamesDbContext dbContext = new GamesDbContext(); var games = dbContext.GamesDb.ToList(); //esta es justo la parte de codigo qure no se como hacerla. /* * NorthwindContext context = new NorthwindContext(); * context.Employees.OrderBy(c => c.FirstName).Load(); * this.dataGrid.ItemsSource = context.Employees.Local; */ }
public async Task PostUser([FromBody] User user) { using (var dbContext = new GamesDbContext()) { var currentUser = await dbContext.User.Where(x => x.Email == user.Email).FirstOrDefaultAsync(); if (currentUser == null) { user.Id = Guid.NewGuid(); await dbContext.Add(user); } else { currentUser.Email = user.Email; currentUser.Name = user.Name; await dbContext.Edit(currentUser); } await dbContext.SaveChangesAsync(); } }
public async Task <IHttpActionResult> PostUser([FromBody] User user, [FromUri] int bestScore = 0) { Guid userId; using (var dbContext = new GamesDbContext()) { var currentUser = await dbContext.User.Where(x => x.Email == user.Email).FirstOrDefaultAsync(); if (currentUser == null) { userId = Guid.NewGuid(); user.Id = userId; await dbContext.Add(user); } else { currentUser.Email = user.Email; currentUser.Name = user.Name; userId = currentUser.Id; await dbContext.Edit(currentUser); } if (bestScore > 0) { var currentGameScore = await dbContext.Score.Where(x => x.UserId == userId && x.ScorePoint == bestScore).FirstOrDefaultAsync(); if (currentGameScore == null) { await dbContext.Add(new Score { UserId = userId, GameId = 1, Id = Guid.NewGuid(), ScorePoint = bestScore }); } } await dbContext.SaveChangesAsync(); return(Ok()); } }
private void MigrateDatabase(IApplicationBuilder app) { using (var scope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { // In Production, use something more resilient scope.ServiceProvider.GetRequiredService <TenantDbContext>().Database.Migrate(); //Try to move this section var tenantService = scope.ServiceProvider.GetRequiredService <ITenantService>(); var names = tenantService.GetAllTenantNames(); foreach (var name in names) { var connectionString = Configuration.GetSection("ConnectionStrings") .GetValue <string>("GamesDbTemplate") .Replace("{tenant}", name); var builder = new DbContextOptionsBuilder <GamesDbContext>(); builder.UseNpgsql(connectionString); var context = new GamesDbContext(builder.Options); context.Database.Migrate(); } } }
public FriendQuery(GamesDbContext context) : base(context) { }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <TenantDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("MultiTenantDb"))); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddTransient <ITenantService, TenantService>(); services.AddScoped((serviceProvider) => { var httpContextAccessor = serviceProvider.GetRequiredService <IHttpContextAccessor>(); if (httpContextAccessor.HttpContext == null) { return(null); } var userId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var userTenant = httpContextAccessor.HttpContext.User.FindFirst(CustomClaimTypes.TenantId)?.Value; var connectionString = Configuration.GetSection("ConnectionStrings").GetValue <string>("GamesDbTemplate") .Replace("{tenant}", userTenant); var tenant = new GamesTenant { Name = userTenant, ConnectionString = connectionString, Subject = userId }; return(tenant); }); services.AddScoped((serviceProvider) => { var tenant = serviceProvider.GetRequiredService <GamesTenant>(); var builder = new DbContextOptionsBuilder <GamesDbContext>(); builder.UseNpgsql(tenant.ConnectionString); return(builder.Options); }); //If Database not exists because a new tenant was registered, create this new one services.AddScoped(serviceProvider => { var options = serviceProvider.GetRequiredService <DbContextOptions <GamesDbContext> >(); var context = new GamesDbContext(options); var exists = ((RelationalDatabaseCreator)context.GetService <IDatabaseCreator>()).Exists(); if (!exists) { context.Database.Migrate(); } return(context); }); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { var authoriyUrl = Configuration.GetSection("IdentityServer").GetValue <string>("Url"); options.Authority = authoriyUrl; options.Audience = "games-api"; options.RequireHttpsMetadata = false; // do not do this in production! }); services.AddMemoryCache(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public GameRepository(GamesDbContext context) { _context = context; UnitOfWork = _context; }
public GamesController(GamesDbContext context) { this.context = context; }
public GamesDbContextSeeder(GamesDbContext context, IWebHostEnvironment environment, ILogger <GamesDbContextSeeder> logger) : base( context, environment, logger) { }
public RatingController() { _dbContext = new GamesDbContext(); }
public GamesController(GamesDbContext dbContext, ILogger <GamesController> logger) { _dbContext = dbContext; _logger = logger; }
// Constructor for controller values public GamesController(GamesDbContext context) { _context = context; }
public GamesGraphQLController(GamesDbContext games) => this.games = games;
public GamesService(GamesDbContext gamesDb) { this.gamesDb = gamesDb; }
public GameQuery(GamesDbContext context) : base(context) { }
public GamesHistoryService(GamesDbContext context) { _context = context; }
public UsersService(GamesDbContext context) { _context = context; }
public GameCredentialRepository(GamesDbContext context) { _context = context; }
public FoldersController(GamesDbContext context) { this.context = context; }
public GamesController(GamesDbContext gamesDbContext, IMapper mapper) { _gamesDbContext = gamesDbContext ?? throw new ArgumentNullException(nameof(gamesDbContext)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); _gamesDbContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; }