// 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()); } }
private async Task <GameSession> GameCreationHandler(GameRoom room, GamerAccount createdByAccount) { // trying to find existing session var sessionExists = _dataContext.GameSessions .Any(i => i.RoomId == room.Id && new[] { GameSessionStates.Playing, GameSessionStates.Registration }.Contains(i.State)); if (sessionExists) { throw new Exception("Нельзя создавать игру там где она уже есть :)"); } var session = new GameSession { RoomId = room.Id, Room = room, State = GameSessionStates.Registration, CreatedByGamerAccountId = createdByAccount.Id, CreatedByGamerAccount = createdByAccount }; await _dataContext.AddAsync(session); await _dataContext.SaveChangesAsync(); return(session); }