Пример #1
0
        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;
 }
Пример #3
0
        public TransactionBehavior(IDbContextManager contextManager, GamesDbContext context)
        {
            _contextManager = contextManager;
            Context         = context;

            _contextManager.RegisterContext(Context);
        }
Пример #4
0
 public GamesDbContextCleaner(GamesDbContext context, IWebHostEnvironment environment, ILogger <GamesDbContextCleaner> logger) : base(
         context,
         environment,
         logger)
 {
     Credentials = context.Set <Credential>();
 }
Пример #5
0
        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);
            }
        }
Пример #6
0
 private static void SeedFriends(GamesDbContext context, List <Friend> friends)
 {
     if (!context.Friends.Any())
     {
         context.AddRange(friends);
         context.SaveChanges();
     }
 }
Пример #7
0
 private static void SeedGames(GamesDbContext context, List <Game> games)
 {
     if (!context.Games.Any())
     {
         context.AddRange(games);
         context.SaveChanges();
     }
 }
Пример #8
0
 //Método constructor
 public App()
 {
     InitializeComponent();
     using (GamesDbContext dbContext = new GamesDbContext())
     {
         dbContext.Database.Migrate();
     }
 }
Пример #9
0
 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());
     }
 }
Пример #10
0
 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()));
     }
 }
Пример #11
0
        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;
             */
        }
Пример #12
0
        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();
            }
        }
Пример #13
0
        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());
            }
        }
Пример #14
0
        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();
                }
            }
        }
Пример #15
0
 public FriendQuery(GamesDbContext context) : base(context)
 {
 }
Пример #16
0
        // 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);
        }
Пример #17
0
 public GameRepository(GamesDbContext context)
 {
     _context   = context;
     UnitOfWork = _context;
 }
Пример #18
0
 public GamesController(GamesDbContext context)
 {
     this.context = context;
 }
Пример #19
0
 public GamesDbContextSeeder(GamesDbContext context, IWebHostEnvironment environment, ILogger <GamesDbContextSeeder> logger) : base(
         context,
         environment,
         logger)
 {
 }
Пример #20
0
 public RatingController()
 {
     _dbContext = new GamesDbContext();
 }
 public GamesController(GamesDbContext dbContext, ILogger <GamesController> logger)
 {
     _dbContext = dbContext;
     _logger    = logger;
 }
Пример #22
0
 // Constructor for controller values
 public GamesController(GamesDbContext context)
 {
     _context = context;
 }
Пример #23
0
 public GamesGraphQLController(GamesDbContext games) => this.games = games;
 public GamesService(GamesDbContext gamesDb)
 {
     this.gamesDb = gamesDb;
 }
Пример #25
0
 public GameQuery(GamesDbContext context) : base(context)
 {
 }
Пример #26
0
 public GamesHistoryService(GamesDbContext context)
 {
     _context = context;
 }
 public UsersService(GamesDbContext context)
 {
     _context = context;
 }
Пример #28
0
 public GameCredentialRepository(GamesDbContext context)
 {
     _context = context;
 }
Пример #29
0
 public FoldersController(GamesDbContext context)
 {
     this.context = context;
 }
Пример #30
0
 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;
 }