示例#1
0
        private Game GenerateMatchOfTeams(string team1, string team2)
        {
            var gameResult = new Game {
                GameName = RandomString(random.Next(8, 20)), PathToLog = "http://kek.com"
            };
            var firstTeam = context.Teams.FirstOrDefault(t => t.Name == team1) ?? new Team {
                CvarcTag = team1, Name = team1
            };
            var secondTeam = context.Teams.FirstOrDefault(t => t.Name == team2) ?? new Team {
                CvarcTag = team2, Name = team2
            };
            var firstTeamGameResult = new TeamGameResult {
                Team = firstTeam, Game = gameResult
            };
            var secondTeamGameResult = new TeamGameResult {
                Team = secondTeam, Game = gameResult
            };
            var result1 = new Result {
                TeamGameResult = firstTeamGameResult, Scores = random.Next(100), ScoresType = "MainScores"
            };
            var result2 = new Result {
                TeamGameResult = firstTeamGameResult, Scores = random.Next(100), ScoresType = "OtherScores"
            };
            var result3 = new Result {
                TeamGameResult = secondTeamGameResult, Scores = random.Next(100), ScoresType = "MainScores"
            };
            var result4 = new Result {
                TeamGameResult = secondTeamGameResult, Scores = random.Next(100), ScoresType = "OtherScores"
            };
            var result = context.Games.Add(gameResult);

            if (!context.Teams.Any(t => t.TeamId == firstTeam.TeamId))
            {
                context.Teams.Add(firstTeam);
            }
            if (!context.Teams.Any(t => t.TeamId == secondTeam.TeamId))
            {
                context.Teams.Add(secondTeam);
            }
            context.TeamGameResults.Add(firstTeamGameResult);
            context.TeamGameResults.Add(secondTeamGameResult);
            context.Results.Add(result1);
            context.Results.Add(result2);
            context.Results.Add(result3);
            context.Results.Add(result4);
            context.SaveChanges();
            return(result.Entity);
        }
示例#2
0
        internal static Game Convert(TeamGameResult result)
        {
            Game game = new Game();

            game.GameId          = result.GameId;
            game.ShortName       = result.ShortName;
            game.HomeTeamHtScore = result.HomeTeamHtScore;
            game.AwayTeamHtScore = result.AwayTeamHtScore;
            game.HomeTeamScore   = result.HomeTeamScore;
            game.AwayTeamScore   = result.AwayTeamScore;
            game.GameDate        = result.GameDate;
            game.CompCupPoId     = result.CompCupPoId;
            game.GameTypeId      = result.GameTypeId;
            game.Ddate           = result.DDate;
            game.Ttime           = result.TTime;
            game.GameStatus      = result.GameStatus;
            game.Comp            = result.Comp;
            return(game);
        }
示例#3
0
        private void AddRandomData()
        {
            var gameResult = new Game {
                GameName = RandomString(random.Next(8, 20)), PathToLog = "C:/"
            };
            var firstTeam = new Team {
                CvarcTag = Guid.NewGuid(), LinkToImage = "qwe", Name = RandomString(random.Next(8, 20))
            };
            var secondTeam = new Team {
                CvarcTag = Guid.NewGuid(), LinkToImage = "qwer", Name = RandomString(random.Next(8, 20))
            };
            var firstTeamGameResult = new TeamGameResult {
                Team = firstTeam, Game = gameResult
            };
            var secondTeamGameResult = new TeamGameResult {
                Team = secondTeam, Game = gameResult
            };
            var result1 = new Result {
                TeamGameResult = firstTeamGameResult, Scores = random.Next(100), ScoresType = "MainScores"
            };
            var result2 = new Result {
                TeamGameResult = firstTeamGameResult, Scores = random.Next(100), ScoresType = "OtherScores"
            };
            var result3 = new Result {
                TeamGameResult = secondTeamGameResult, Scores = random.Next(100), ScoresType = "MainScores"
            };
            var result4 = new Result {
                TeamGameResult = secondTeamGameResult, Scores = random.Next(100), ScoresType = "OtherScores"
            };

            context.Games.Add(gameResult);
            context.Teams.Add(firstTeam);
            context.Teams.Add(secondTeam);
            context.TeamGameResults.Add(firstTeamGameResult);
            context.TeamGameResults.Add(secondTeamGameResult);
            context.Results.Add(result1);
            context.Results.Add(result2);
            context.Results.Add(result3);
            context.Results.Add(result4);
            context.SaveChanges();
        }
示例#4
0
        public async Task <ReadOnlyCollection <TeamGameResult> > GetGamesAsync(int teamId,
                                                                               int seasonId)
        {
            List <TeamGameResult> games = new List <TeamGameResult>();

            using (var context = new DatabaseContext())
            {
                List <InternalModel.StoredProcedureResults.TeamGameResult> databaseGames = await context.Database.SqlQuery <InternalModel.StoredProcedureResults.TeamGameResult>(
                    "dbo.api_GetTeamGames_asc @teamId, @seasonId",
                    new SqlParameter("teamId", teamId),
                    new SqlParameter("seasonId", seasonId)).ToListAsync();

                List <int> teamIds = GetGameIds(databaseGames);
                List <InternalModel.Team> teams = await context.Teams.Where(t => teamIds.Contains(t.TeamId)).ToListAsync();

                InternalModel.Season season = await context.Seasons.FirstOrDefaultAsync(s => s.SeasonId == seasonId);

                List <int>      divisionIds = databaseGames.Select(d => d.DivisionId).Distinct().ToList();
                List <Division> divisions   =
                    await context.Divisions.Where(d => divisionIds.Contains(d.DivisionId)).ToListAsync();

                List <int>   venueIds = databaseGames.Select(v => v.VenueId).Distinct().ToList();
                List <Venue> venues   = await context.Venues.Where(v => venueIds.Contains(v.VenueId)).ToListAsync();

                foreach (InternalModel.StoredProcedureResults.TeamGameResult result in databaseGames)
                {
                    Division division = divisions.FirstOrDefault(d => d.DivisionId == result.DivisionId);
                    Venue    venue    = venues.FirstOrDefault(v => v.VenueId == result.VenueId);

                    TeamGameResult game = new TeamGameResult(
                        result.ShortName,
                        result.GameId,
                        result.HomeTeamId,
                        Team.Convert(teams.SingleOrDefault(t => t.TeamId == result.HomeTeamId)),
                        result.AwayTeamId,
                        Team.Convert(teams.SingleOrDefault(t => t.TeamId == result.AwayTeamId)),
                        result.HomeTeamHtScore,
                        result.AwayTeamHtScore,
                        result.HomeTeamScore,
                        result.AwayTeamScore,
                        result.GameDate,
                        ExternalModel.Venue.Convert(venue),
                        ExternalModel.Division.Convert(division),
                        result.DDate,
                        result.TTime,
                        result.GameStatus,
                        result.Comp,
                        result.CompCupPoId,
                        result.GameTypeId,
                        result.SeasonId,
                        result.SeasonName,
                        Season.Convert(season),
                        result.HomeTeamName,
                        result.AwayTeamName);

                    games.Add(game);
                }
            }

            return(new ReadOnlyCollection <TeamGameResult>(games));
        }
示例#5
0
        protected object JSONSetGameResult(string data, Dictionary <string, object> sessionData)
        {
            Dictionary <string, object> resultData;

            if (data == null)
            {
                throw new HttpException(400, "Bad Request");
            }
            try
            {
                resultData = (Dictionary <string, object>)jsonSerializer.DeserializeObject(data);
            }
            catch
            {
                throw new HttpException(400, "Bad Request");
            }
            if (resultData == null || !resultData.ContainsKey("GameId") || !(resultData["GameId"] is int))
            {
                throw new HttpException(400, "Bad Request");
            }
            int id = (int)resultData["GameId"];

            if (Controller.Tournament != null && Controller.Tournament.GamesById != null)
            {
                Game game = null;
                if (Controller.Tournament.GamesById.ContainsKey(id))
                {
                    game = Controller.Tournament.GamesById[id];
                }

                if (game != null)
                {
                    if (game.ScoreKeeper == null || game.ScoreKeeper.AssociatedAccessCode != getAccessCode(sessionData))
                    {
                        throw new HttpException(403, "Forbidden");
                    }

                    bool shouldTriggerGameResultChanged = false;
                    try
                    {
                        if (game.IsConfirmed)
                        {
                            game.IsConfirmed = false;
                            shouldTriggerGameResultChanged = true;
                        }
                        if (resultData.ContainsKey("TeamGameResults"))
                        {
                            #region Team game results
                            object teamGameResults = resultData["TeamGameResults"];
                            if (teamGameResults != null)
                            {
                                if (teamGameResults is Dictionary <string, object> )
                                {
                                    foreach (KeyValuePair <string, object> pair in (Dictionary <string, object>)teamGameResults)
                                    {
                                        if (!(pair.Value is Dictionary <string, object>))
                                        {
                                            throw new HttpException(400, "Bad Request");
                                        }

                                        Dictionary <string, object> teamGameResultData = (Dictionary <string, object>)pair.Value;
                                        string teamId = pair.Key;
                                        if (!game.TeamGameResults.ContainsKey(teamId))
                                        {
                                            throw new HttpException(404, "Not Found");
                                        }

                                        TeamGameResult teamGameResult = game.TeamGameResults[teamId];
                                        if (teamGameResult == null)
                                        {
                                            throw new HttpException(404, "Not Found");
                                        }


                                        if (teamGameResultData.ContainsKey("NumPoints"))
                                        {
                                            if (teamGameResultData["NumPoints"] != null)
                                            {
                                                if (teamGameResultData["NumPoints"] is int)
                                                {
                                                    int numPoints = (int)teamGameResultData["NumPoints"];
                                                    if (teamGameResult.NumPoints != numPoints)
                                                    {
                                                        teamGameResult.NumPoints       = numPoints;
                                                        shouldTriggerGameResultChanged = true;
                                                    }
                                                }
                                                else
                                                {
                                                    throw new HttpException(400, "Bad Request");
                                                }
                                            }
                                        }

                                        if (teamGameResultData.ContainsKey("NumFouls"))
                                        {
                                            if (teamGameResultData["NumFouls"] != null)
                                            {
                                                if (teamGameResultData["NumFouls"] is int)
                                                {
                                                    int numFouls = (int)teamGameResultData["NumFouls"];
                                                    if (teamGameResult.NumFouls != numFouls)
                                                    {
                                                        teamGameResult.NumFouls        = numFouls;
                                                        shouldTriggerGameResultChanged = true;
                                                    }
                                                }
                                                else
                                                {
                                                    throw new HttpException(400, "Bad Request");
                                                }
                                            }
                                        }

                                        if (teamGameResultData.ContainsKey("WonGame"))
                                        {
                                            if (teamGameResultData["WonGame"] != null)
                                            {
                                                if (teamGameResultData["WonGame"] is bool)
                                                {
                                                    bool wonGame = (bool)teamGameResultData["WonGame"];
                                                    if (teamGameResult.WonGame != wonGame)
                                                    {
                                                        teamGameResult.WonGame         = wonGame;
                                                        shouldTriggerGameResultChanged = true;
                                                    }
                                                }
                                                else
                                                {
                                                    throw new HttpException(400, "Bad Request");
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    throw new HttpException(400, "Bad Request");
                                }
                            }
                            #endregion
                        }

                        if (resultData.ContainsKey("WinningTeam"))
                        {
                            object winningTeam = resultData["WinningTeam"];
                            if (winningTeam != null)
                            {
                                RoundRobinTeamData teamData = Controller.Tournament.getTeamDataById(winningTeam.ToString().Trim());
                                if (teamData != null)
                                {
                                    if (game.WinningTeam != teamData.Team)
                                    {
                                        game.WinningTeam = teamData.Team;
                                        shouldTriggerGameResultChanged = true;
                                    }
                                }
                                else
                                {
                                    throw new HttpException(404, "Not Found");
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (shouldTriggerGameResultChanged)
                        {
                            Controller.TriggerGameResultChanged(game);
                        }
                    }
                }
                else
                {
                    throw new HttpException(404, "Not Found");
                }
            }
            else
            {
                throw new HttpException(404, "Not Found");
            }

            return(null);
        }
 public TeamGameResultWebData(TeamGameResult teamGameResult)
 {
     _teamGameResult = teamGameResult;
 }