コード例 #1
0
 private Game GetGameByGameNumber(string gameNumber, AntwerpRCEntities context)
 {
     return context.Game.FirstOrDefault(g => g.GameNumber == gameNumber);
 }
コード例 #2
0
        private Game ProcessGameRow(HtmlNode row, DateTime date, List<TeamClub> teamClubs, AntwerpRCEntities context, string user)
        {
            Game game = null;
            string gameNumber;
            //Find the game number
            var gameNrNode = row.Descendants("td").FirstOrDefault();
            if (gameNrNode != null && !string.IsNullOrEmpty(gameNrNode.InnerText.CleanHtml().Trim()))
            {
                gameNumber = gameNrNode.InnerText.CleanHtml();
                game = GetGameByGameNumber(gameNumber, context);
            }
            else
            {
                return null;
            }

            if (game == null)
            {
                game = new Game {GameNumber = gameNumber, Date = date, AuditCreatedBy = user, AuditCreatedOn = DateTime.Now};
                //Check the date

                var newDateNode = row.Descendants("td").LastOrDefault();
                if (newDateNode != null && !string.IsNullOrEmpty(newDateNode.InnerText))
                {
                    DateTime newDate;
                    if (DateTime.TryParse(newDateNode.InnerText.CleanHtml(), out newDate))
                        game.Date = newDate;
                }

                //Find the first team
                var team1Node = row.Descendants("td").Skip(1).Take(1).FirstOrDefault();
                if (team1Node != null && !string.IsNullOrEmpty(team1Node.InnerText))
                {
                    var teamClub1 = teamClubs.FirstOrDefault(t => t.Club.ClubName == team1Node.InnerText.CleanHtml().Trim() || t.Club.ClubAlias.Any(a => a.Alias == team1Node.InnerText.CleanHtml().Trim()));
                    if (teamClub1 != null)
                    {
                        game.TeamClub1Id = teamClub1.TeamClubId;
                        game.TeamClub1AddressId = teamClub1.Club.Address.First().AddressId;
                    }
                }

                //find the second team
                var team2Node = row.Descendants("td").Skip(2).Take(1).FirstOrDefault();
                if (team2Node != null && !string.IsNullOrEmpty(team2Node.InnerText))
                {
                    var teamClub2 = teamClubs.FirstOrDefault(t => t.Club.ClubName == team2Node.InnerText.CleanHtml().Trim() || t.Club.ClubAlias.Any(a => a.Alias == team2Node.InnerText.CleanHtml().Trim()));
                    if (teamClub2 != null)
                        game.TeamClub2Id = teamClub2.TeamClubId;
                }
            }

            //Find the score
            var scoreNode = row.Descendants("td").Skip(4).Take(1).FirstOrDefault();
            int team1Score = -999;
            int team2Score = -999;

            if (scoreNode != null && !string.IsNullOrEmpty(scoreNode.InnerText.CleanHtml().Trim()))
            {
                string[] scores = scoreNode.InnerText.CleanHtml().Trim().Split('-');
                if (!int.TryParse(scores[0].Trim(), out team1Score))
                {
                    //Check for FF
                    if (scores[0].Trim().Equals("FF", StringComparison.InvariantCultureIgnoreCase))
                    {
                        team1Score = -1;
                    }
                }
                if (!int.TryParse(scores[1].Trim(), out team2Score))
                {
                    //Check for FF
                    if (scores[1].Trim().Equals("FF", StringComparison.InvariantCultureIgnoreCase))
                    {
                        team2Score = -1;
                    }
                }
            }
            game.TeamClub1Score = team1Score;
            game.TeamClub2Score = team2Score;

            //Find the try count
            int team1Try = 0;
            int team2Try = 0;

            var tryNode = row.Descendants("td").Skip(5).Take(1).FirstOrDefault();
            if (tryNode != null && !string.IsNullOrEmpty(tryNode.InnerText.CleanHtml().Trim()))
            {
                string[] scores = tryNode.InnerText.CleanHtml().Trim().Split('-');
                int.TryParse(scores[0].Trim(), out team1Try);
                int.TryParse(scores[1].Trim(), out team2Try);
            }
            game.TeamClub1Tries = team1Try;
            game.TeamClub2Tries = team2Try;

            return game;
        }