// saves new Game object in database and returns partial view with info about game and links for opponent public ActionResult Create(string name) { // TODO: create fail view when there is no chosenSymbol in session state var symbol = (Symbol) Session["ChosenSymbol"]; var player = new Player() { Name = name, Symbol = symbol }; var game = new Game() { Player1 = player, Player2 = null }; using (var context = new GameDbContext()) { context.Players.Add(player); context.Games.Add(game); context.SaveChanges(); } return PartialView(game); }
public static async Task <List <GameUser> > GetGameUsers() { await using var dbContext = new GameDbContext(); var users = await dbContext.GameUsers.ToListAsync().ConfigureAwait(false); return(users); }
public static async Task <GameUser> GetGameUser(ulong discordId) { await using var dbContext = new GameDbContext(); var gameUser = await dbContext.GameUsers.FirstOrDefaultAsync(x => x.DiscordUserId == discordId); return(gameUser); }
public override async Task <IdentityResult> UpdateAsync(UserModel user) { using (var dbContext = new GameDbContext(_dbContextOptions)) { var current = await dbContext.Set <UserModel>().FirstOrDefaultAsync(x => x.Id == user.Id); current.AccessFailedCount = user.AccessFailedCount; current.ConcurrencyStamp = user.ConcurrencyStamp; current.Email = user.Email; current.EmailConfirmationDate = user.EmailConfirmationDate; current.EmailConfirmed = user.EmailConfirmed; current.FirstName = user.FirstName; current.LastName = user.LastName; current.LockoutEnabled = user.LockoutEnabled; current.NormalizedEmail = user.NormalizedEmail; current.NormalizedUserName = user.NormalizedUserName; current.PhoneNumber = user.PhoneNumber; current.PhoneNumberConfirmed = user.PhoneNumberConfirmed; current.Score = user.Score; current.SecurityStamp = user.SecurityStamp; current.TwoFactorEnabled = user.TwoFactorEnabled; current.UserName = user.UserName; await dbContext.SaveChangesAsync(); return(IdentityResult.Success); } }
public GameController(GameDbContext ctx, int gameId) { _context = ctx; CurrentGame = ctx.Games.Include(g => g.Cells) .Single(g => g.GameId == gameId); Board = LoadBoard(); }
public bool IsCharacterOwned(string user, string character) { using (var c = new GameDbContext()) { AccountCharacter ac = c.AccountsEx.Find(user); if (ac.GameID1 != null && ac.GameID1.Equals(character)) { return(true); } if (ac.GameID2 != null && ac.GameID2.Equals(character)) { return(true); } if (ac.GameID3 != null && ac.GameID3.Equals(character)) { return(true); } if (ac.GameID4 != null && ac.GameID4.Equals(character)) { return(true); } if (ac.GameID5 != null && ac.GameID5.Equals(character)) { return(true); } } return(false); }
public override async Task <bool> VerifyTwoFactorTokenAsync(UserModel user, string tokenProvider, string token) { using (var dbContext = new GameDbContext(_dbContextOptions)) { return(await dbContext.TwoFactorCodeModels.AnyAsync(x => x.TokenProvider == tokenProvider && x.TokenCode == token && x.UserId == user.Id)); } }
public bool AddGame(string name, string image, double size, decimal price, string url, string description, DateTime releaseDate) { using (var db = new GameDbContext()) { if (db.Games.Any(p => p.Title == name)) { return(false); } var game = new Game { Title = name, Description = description, ImageThumbnail = image, YouTubeVideoId = url, Size = size, Price = price, ReleaseDate = releaseDate }; db.Add(game); db.SaveChanges(); } return(true); }
public GamesController(GameDbContext context, UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager) { _context = context; _userManager = userManager; _signInManager = signInManager; }
public async Task <bool> IsUserExisting(string email) { using (var gameDbContext = new GameDbContext(_dbContextOptions)) { return(await gameDbContext.UserModels.AnyAsync(user => user.Email == email)); } }
public bool isUserEsis(string email) { using (var gameDbContext = new GameDbContext(_dbContextOptions)) { return(gameDbContext.UserModels.Any(user => user.Email == email)); } }
public async Task <IEnumerable <UserModel> > GetTopUsers(int numberOfUsers) { using (var gameDbContext = new GameDbContext(_dbContextOptions)) { return(await gameDbContext.UserModels.OrderByDescending(x => x.Score).ToListAsync()); } }
public async Task <UserModel> GetUserByEmail(string email) { using (var db = new GameDbContext(_dbContextOptions)) { return(await db.UserModels.FirstOrDefaultAsync(x => x.Email == email)); } }
public GameService(IFrontend frontend, GameDbContext dataContext, GameSettings gameSettings) { _frontend = frontend; _dataContext = dataContext; _gameSettings = gameSettings; _minimalGamerCount = _gameSettings.MinGamerCount < 4 ? 4 : _gameSettings.MinGamerCount; }
public void TestUpdate_ShouldUpdateGameById() { var options = new DbContextOptionsBuilder <GameDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new GameDbContext(options); SeedData(context); var repository = new GameRepository(context); var gameToUpdate = repository.GetById(1); gameToUpdate.Title = "Lorem"; var actualState = context.Entry(gameToUpdate).State; repository.Update(gameToUpdate); EntityState expectedState = EntityState.Modified; Assert.Equal(expectedState, actualState); }
public override async Task <UserModel> FindByIdAsync(string userId) { using var dbContext = new GameDbContext(_dbContextOptions); Guid id = Guid.Parse(userId); return(await dbContext.Set <UserModel>().FirstOrDefaultAsync(x => x.Id == id)); }
public ICollection <Character> GetCharsFor(string user) { using (var c = new GameDbContext()) { return(c.Characters.Where(a => a.AccountID == user).ToArray <Character>()); } }
public bool IsAdmin(string email) { using (var context = new GameDbContext()) { return(context.Users.Any(p => p.Email == email && p.IsAdmin)); } }
public Warehouse GetVaultFor(string account) { using (var c = new GameDbContext()) { return(c.Vaults.Find(account)); } }
public bool Find(string email, string password) { using (var context = new GameDbContext()) { return(context.Users.Any(p => p.Email == email && p.Password == password)); } }
public override async Task <UserModel> FindByEmailAsync(string email) { using (var dbContext = new GameDbContext(_dbContextOptions)) { return(await dbContext.Set <UserModel>().FirstOrDefaultAsync(x => x.Email == email)); } }
public async Task <IActionResult> Rate(RateGameViewModel vm) { var currentUser = await _userManager.GetUserAsync(HttpContext.User); if (currentUser == null) { return(RedirectToAction("Index", "Home")); } using (var db = new GameDbContext(((Server)_server).ConnectionString)) { var review = db.Reviews.FirstOrDefault(r => r.UserId.ToString().Equals(currentUser.Id) && r.Game.Name.Equals(vm.GameName)); if (review == null) { review = new Review { Id = Guid.NewGuid(), UserId = Guid.Parse(currentUser.Id), Game = db.Games.First(g => g.Name.Equals(vm.GameName)), Rating = 0, Comment = "" }; db.Reviews.Add(review); } review.Rating = vm.Rating; review.Comment = vm.Comment; db.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
public void TestAddGames_ShouldAddGame() { var options = new DbContextOptionsBuilder <GameDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new GameDbContext(options); SeedData(context); var repository = new GameRepository(context); var game = new Game() { Id = 3, Title = "fdf", Price = 13m, Rating = 2, Description = "dsdqsfdfsfsdsd", Platform = "ds", Manufacturer = new Manufacturer() { Name = "ivfdan" }, ReleaseDate = DateTime.UtcNow.AddDays(12), Image = new byte[] { 1, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1 } }; repository.Add(game); var expectedResult = context.Games.Count(); Assert.Equal(expectedResult, repository.Count()); }
// ITEMS public async Task <IItem> NewItemAsync(IGame game, IItem item) { // use some sort of mapper? to clean this up? var gridItem = (GridItem)item; var dbItem = new DbItem() { RecordBy = "notlinktoausercontextyet", RecordDate = DateTimeOffset.Now, Name = item.Name, Description = item.Description, ItemTypes = gridItem.ItemTypes.Select(it => new DbItemTypes() { ItemType = it }).ToList() }; using (var context = new GameDbContext()) { var trackedItem = await context.Items.AddAsync(dbItem); await context.SaveChangesAsync(); return(trackedItem.Entity.ToItem()); } }
public async Task UpdateSpawnersAsync(IGame game, IEnumerable <ISpawner> spawners) { var toGet = spawners.Select(item => item.Id).ToList(); using (var context = new GameDbContext()) { var dbSpawners = await context.Spawners.Where(s => toGet.Contains(s.Id)).ToListAsync(); if (dbSpawners.Count == 0) { return; } foreach (GridSpawner spawner in spawners) { var dbSpawner = dbSpawners.FirstOrDefault(s => s.Id == spawner.Id); if (dbSpawner == null) { continue; } // should we save as new here? .. right now i wont so the current world can hold temporary spawners from events etc etc. dbSpawner.Delay = spawner.ResetDuration; dbSpawner.MapId = spawner.MapId; dbSpawner.EntityId = spawner.Id; dbSpawner.ModifiedBy = "nousercontextyet"; dbSpawner.ModifiedDate = DateTime.Now; dbSpawner.SpawnType = (byte)spawner.SpawnType; context.Spawners.Update(dbSpawner); } await context.SaveChangesAsync(); } }
// MAPS public async Task <IMap> NewMapAsync(IGame game, IMap map) { var gridMap = (GridMap)map; var dbMap = new DbMap() { RecordBy = "notlinktoausercontextyet", RecordDate = DateTimeOffset.Now, Name = map.Name, Description = map.Description, LocationX = gridMap.Location.X, LocationY = gridMap.Location.Y, LocationZ = gridMap.Location.Z, Exits = gridMap.Exits.Distinct().Select(exit => new DbMapExit() { Direction = (byte)exit }).ToList() }; using (var context = new GameDbContext()) { var savedMap = await context.AddAsync(dbMap); await context.SaveChangesAsync(); return(savedMap.Entity.ToMap()); } }
// PLAYERS public async Task <IPlayer> LoadPlayerAsync(IGame game, string name, string pass) { using (var dbContext = new GameDbContext()) { var dbPlayer = await dbContext.Players .Include(player => player.Class) .Include(e => e.Class).ThenInclude(e => e.Actions).ThenInclude(a => a.Action).ThenInclude(a => a.ElementType).ThenInclude(e => e.Ranges) .Include(e => e.Class).ThenInclude(e => e.Actions).ThenInclude(a => a.Action).ThenInclude(a => a.Modifiers) .Include(e => e.Class).ThenInclude(e => e.Actions).ThenInclude(a => a.Requirements) .Include(player => player.Stats) .Include(player => player.Items).ThenInclude(item => item.Stats) .Include(player => player.Items).ThenInclude(item => item.BaseItem).ThenInclude(baseitem => baseitem.ItemTypes) .FirstOrDefaultAsync(o => o.Name.ToLower().Trim() == name.ToLower().Trim()); if (dbPlayer == null) { _logger.LogWarning($"Attempted to load player that doesn't exist"); return(null); } var isAuthenticated = PasswordStorage.VerifyPassword(pass, dbPlayer.Password); if (!isAuthenticated) { return(null); } // need to refactor out these conversions return(dbPlayer.ToPlayer(game)); }; }
public async Task <IEnumerable <IMap> > LoadMapsAsync(IGame game) { using (var dbContext = new GameDbContext()) { return(await dbContext.Maps.Include(m => m.Exits).Select(m => m.ToMap()).ToListAsync()); } }
public void Can_track_an_entity_with_more_than_10_properties() { using (var testDatabase = OracleTestStore.CreateInitialized(DatabaseName)) { var options = Fixture.CreateOptions(testDatabase); using (var context = new GameDbContext(options)) { context.Database.EnsureCreated(); context.Characters.Add(new PlayerCharacter(new Level { Game = new Game() })); context.SaveChanges(); } using (var context = new GameDbContext(options)) { var character = context.Characters .Include(c => c.Level.Game) .OrderBy(c => c.Id) .First(); Assert.NotNull(character.Game); Assert.NotNull(character.Level); Assert.NotNull(character.Level.Game); } } }
public SerializationContext( GameDbContext dbContext, GameEntity observer, GameServices services) { DbContext = dbContext; Observer = observer; Manager = observer.Manager; Services = services; }
public IActionResult Index() { using (var db = new GameDbContext()) { var allGames = db.Games.ToList(); return(View(allGames)); } }
public ActionResult Submit(int id, string name) { var symbol = (Symbol) Session["ChosenSymbol"]; var player = new Player() { Name = name, Symbol = symbol }; using (var context = new GameDbContext()) { var game = context.Games .Include(g => g.Player1) .Include(g => g.Player2) .SingleOrDefault(g => g.Id == id); if (game == null) { game = new Game(); game.Player1 = player; // TODO: przemyśl czy: // TODO: - powinieneś trzymać referencję do DataLoader w tym obiekcie, czy tworzyć każdorazowo, gdy jest potrzebny // TODO: - jw. z BasicUrlGenerator context.Players.Add(player); context.Games.Add(game); context.SaveChanges(); var urlGenerator = new BasicUrlGenerator(); game.RefLink = urlGenerator.GetUrl(game.Id); context.SaveChanges(); return PartialView("~/Views/NewLayout/Create.cshtml", game); } else { game.Player2 = player; context.Players.Add(player); context.SaveChanges(); return PartialView("~/Views/NewLayout/ShowPartial.cshtml", game); } } }