コード例 #1
0
        public void CalculateTeamResult(TeamMatch team, TeamMatch teamAgainst, int seasonId)
        {
            using (var dc = ThaitaeDataDataContext.Create())
            {
                var teamUpdate = dc.TeamSeasons.Single(item => item.TeamId == team.TeamId && item.SeasonId == seasonId);
                teamUpdate.TeamMatchPlayed = dc.TeamMatches.Count(item => item.TeamId == team.TeamId && item.TeamStatus != 0);
                teamUpdate.TeamDrew = dc.TeamMatches.Count(item => item.TeamId == team.TeamId && item.TeamStatus == 2);
                var teamgoalAgainstSum =
                    dc.TeamMatches.Where(item => item.TeamId == team.TeamId && item.SeasonId == seasonId && item.TeamStatus != 0).Sum(
                        item => item.TeamGoalAgainst);
                if (teamgoalAgainstSum != null)
                    teamUpdate.TeamGoalAgainst = (int)teamgoalAgainstSum;

                var teamgoalForSum =
                    dc.TeamMatches.Where(item => item.TeamId == team.TeamId && item.SeasonId == seasonId && item.TeamStatus != 0).Sum(
                        item => item.TeamGoalFor);
                if (teamgoalForSum != null)
                    teamUpdate.TeamGoalFor = (int)teamgoalForSum;
                teamUpdate.TeamGoalDiff = teamUpdate.TeamGoalFor - teamUpdate.TeamGoalAgainst;
                teamUpdate.TeamLoss = dc.TeamMatches.Count(item => item.TeamId == team.TeamId && item.SeasonId == seasonId && item.TeamStatus == 3);
                teamUpdate.TeamWon = dc.TeamMatches.Count(item => item.TeamId == team.TeamId && item.SeasonId == seasonId && item.TeamStatus == 1);
                teamUpdate.TeamPts = (teamUpdate.TeamWon * 3) + (teamUpdate.TeamDrew);

                var teamUpdateYellowCard = 0;
                var teamUpdateRedCard = 0;
                var playersUpdate = dc.Players.Where(item => item.TeamId == teamUpdate.TeamId && item.SeasonId == teamUpdate.SeasonId);
                if (playersUpdate.Count() != 0)
                {
                    teamUpdateYellowCard = playersUpdate.Sum(item => item.PlayerYellowCard);
                    teamUpdateRedCard = playersUpdate.Sum(item => item.PlayerRedCard);
                }

                teamUpdate.TeamYellowCard = teamUpdateYellowCard;
                teamUpdate.TeamRedCard = teamUpdateRedCard;
                var teamAgainstUpdate = dc.TeamSeasons.Single(item => item.TeamId == teamAgainst.TeamId && item.SeasonId == seasonId);
                teamAgainstUpdate.TeamMatchPlayed = dc.TeamMatches.Count(item => item.TeamId == teamAgainst.TeamId && item.SeasonId == seasonId && item.TeamStatus != 0);
                teamAgainstUpdate.TeamDrew = dc.TeamMatches.Count(item => item.TeamId == teamAgainst.TeamId && item.SeasonId == seasonId && item.TeamStatus == 2);
                var teamAgainstgoalAgainstSum =
                    dc.TeamMatches.Where(item => item.TeamId == teamAgainst.TeamId && item.SeasonId == seasonId && item.TeamStatus != 0).Sum(
                        item => item.TeamGoalAgainst);
                if (teamAgainstgoalAgainstSum != null)
                    teamAgainstUpdate.TeamGoalAgainst = (int)teamAgainstgoalAgainstSum;

                var teamAgainstgoalForSum =
                    dc.TeamMatches.Where(item => item.TeamId == teamAgainst.TeamId && item.SeasonId == seasonId && item.TeamStatus != 0).Sum(
                        item => item.TeamGoalFor);
                if (teamAgainstgoalForSum != null)
                    teamAgainstUpdate.TeamGoalFor = (int)teamAgainstgoalForSum;
                teamAgainstUpdate.TeamGoalDiff = teamAgainstUpdate.TeamGoalFor - teamAgainstUpdate.TeamGoalAgainst;
                teamAgainstUpdate.TeamLoss = dc.TeamMatches.Count(item => item.TeamId == teamAgainst.TeamId && item.SeasonId == seasonId && item.TeamStatus == 3);
                teamAgainstUpdate.TeamWon = dc.TeamMatches.Count(item => item.TeamId == teamAgainst.TeamId && item.SeasonId == seasonId && item.TeamStatus == 1);
                teamAgainstUpdate.TeamPts = (teamAgainstUpdate.TeamWon * 3) + (teamAgainstUpdate.TeamDrew);

                var teamAgainstYellowCard = 0;
                var teamAgainstRedCard = 0;
                var playersAgainst =
                    dc.Players.Where(
                        item => item.TeamId == teamAgainstUpdate.TeamId && item.SeasonId == teamAgainstUpdate.SeasonId);
                if (playersAgainst.Count() != 0)
                {
                    teamAgainstYellowCard = playersAgainst.Sum(item => item.PlayerYellowCard);
                    teamAgainstRedCard = playersAgainst.Sum(item => item.PlayerRedCard);
                }

                teamAgainstUpdate.TeamYellowCard = teamAgainstYellowCard;
                teamAgainstUpdate.TeamRedCard = teamAgainstRedCard;
                dc.SubmitChanges();
            }
        }
コード例 #2
0
        protected void JqgridMatch1_RowAdding(object sender, JQGridRowAddEventArgs e)
        {
            var homeId = String.IsNullOrEmpty(e.RowData["TeamHomeIdNameExtend"])
                                ? 0
                                : Convert.ToInt32(e.RowData["TeamHomeIdNameExtend"]);
            var awayId = String.IsNullOrEmpty(e.RowData["TeamAwayIdNameExtend"])
                                ? 0
                                : Convert.ToInt32(e.RowData["TeamAwayIdNameExtend"]);
            var date = String.IsNullOrEmpty(e.RowData["MatchDate"])
                           ? DateTime.Now
                           : Convert.ToDateTime(e.RowData["MatchDate"]);
            if (homeId == 0 || awayId == 0 || Convert.ToInt32(Session["seasonid"]) == 0) return;
            using (var dc = ThaitaeDataDataContext.Create())
            {
                var match1 = new Match
                {
                    MatchDate = date,
                    SeasonId = Convert.ToInt32(Session["seasonid"]),
                    TeamHomeId = homeId,
                    TeamAwayId = awayId
                };
                var match2 = new Match
                {
                    MatchDate = date,
                    SeasonId = Convert.ToInt32(Session["seasonid"]),
                    TeamHomeId = awayId,
                    TeamAwayId = homeId
                };
                dc.Matches.InsertOnSubmit(match2);
                dc.Matches.InsertOnSubmit(match1);
                dc.SubmitChanges();
                var teamHome1 = new TeamMatch
                {
                    TeamId = homeId,
                    TeamGoalFor = 0,
                    TeamGoalPenalty = 0,
                    TeamHome = 1,
                    SeasonId = Convert.ToInt32(Session["seasonid"]),
                    MatchId = match1.MatchId
                };

                var teamAway1 = new TeamMatch
                {
                    TeamId = awayId,
                    TeamGoalFor = 0,
                    TeamGoalPenalty = 0,
                    TeamHome = 0,
                    SeasonId = Convert.ToInt32(Session["seasonid"]),
                    MatchId = match1.MatchId
                };

                var teamHome2 = new TeamMatch
                {
                    TeamId = awayId,
                    TeamGoalFor = 0,
                    TeamGoalPenalty = 0,
                    TeamHome = 1,
                    SeasonId = Convert.ToInt32(Session["seasonid"]),
                    MatchId = match2.MatchId
                };

                var teamAway2 = new TeamMatch
                {
                    TeamId = homeId,
                    TeamGoalFor = 0,
                    TeamGoalPenalty = 0,
                    TeamHome = 0,
                    SeasonId = Convert.ToInt32(Session["seasonid"]),
                    MatchId = match2.MatchId
                };
                dc.TeamMatches.InsertOnSubmit(teamHome1);
                dc.TeamMatches.InsertOnSubmit(teamHome2);
                dc.TeamMatches.InsertOnSubmit(teamAway1);
                dc.TeamMatches.InsertOnSubmit(teamAway2);
                dc.SubmitChanges();
            }
        }
コード例 #3
0
 public void GenerateMatch(int seasonId)
 {
     using (var dc = ThaitaeDataDataContext.Create())
     {
         var isChampionLeagueFinal = dc.Leagues.Any(item => item.LeagueId == Convert.ToInt32(Session["leagueid"]) && (item.LeagueType == 1 || item.LeagueType == 2));
         if (!isChampionLeagueFinal)
         {
             var teamSeasonList =
                 dc.TeamSeasons.Join(dc.Teams, teamSeason => teamSeason.TeamId, team => team.TeamId,
                                     (teamSeason, team) => new { teamSeason.SeasonId, team.TeamId })
                   .Where(teamSeason => teamSeason.SeasonId == seasonId)
                   .ToList();
             for (var i = 0; i < teamSeasonList.Count; i++)
             {
                 for (var j = 0; j < teamSeasonList.Count; j++)
                 {
                     if (teamSeasonList[i].TeamId != teamSeasonList[j].TeamId)
                     {
                         Match match = null;
                         var matchExist = dc.Matches.Count(
                             item =>
                             item.SeasonId == seasonId && item.TeamHomeId == teamSeasonList[i].TeamId &&
                             item.TeamAwayId == teamSeasonList[j].TeamId);
                         if (matchExist == 0)
                         {
                             match = new Match
                                 {
                                     SeasonId = seasonId,
                                     MatchDate = DateTime.Now,
                                     TeamHomeId = teamSeasonList[i].TeamId,
                                     TeamAwayId = teamSeasonList[j].TeamId
                                 };
                             dc.Matches.InsertOnSubmit(match);
                             dc.SubmitChanges();
                         }
                         else
                         {
                             match = dc.Matches.Single(
                                 item =>
                                 item.SeasonId == seasonId && item.TeamHomeId == teamSeasonList[i].TeamId &&
                                 item.TeamAwayId == teamSeasonList[j].TeamId);
                         }
                         var teamHomeExist =
                             dc.TeamMatches.Count(
                                 item => item.MatchId == match.MatchId && item.TeamId == match.TeamHomeId);
                         if (teamHomeExist == 0)
                         {
                             var teamHomeMatch = new TeamMatch
                                 {
                                     MatchId = match.MatchId,
                                     TeamId = match.TeamHomeId,
                                     TeamHome = 1,
                                     SeasonId = match.SeasonId
                                 };
                             dc.TeamMatches.InsertOnSubmit(teamHomeMatch);
                             dc.SubmitChanges();
                         }
                         var teamAwayExist =
                             dc.TeamMatches.Count(
                                 item => item.MatchId == match.MatchId && item.TeamId == match.TeamAwayId);
                         if (teamAwayExist == 0)
                         {
                             var teamAwayMatch = new TeamMatch
                                 {
                                     MatchId = match.MatchId,
                                     TeamId = match.TeamAwayId,
                                     TeamHome = 0,
                                     SeasonId = match.SeasonId
                                 };
                             dc.TeamMatches.InsertOnSubmit(teamAwayMatch);
                             dc.SubmitChanges();
                         }
                     }
                 }
             }
         }
         else
         {
             var isFinished = SeasonHelper.CheckGroupSeasonIsFinnish(seasonId);
         }
     }
 }
コード例 #4
0
 partial void DeleteTeamMatch(TeamMatch instance);
コード例 #5
0
 partial void UpdateTeamMatch(TeamMatch instance);
コード例 #6
0
 partial void InsertTeamMatch(TeamMatch instance);
コード例 #7
0
		private void detach_TeamMatches(TeamMatch entity)
		{
			this.SendPropertyChanging();
			entity.Team = null;
		}
コード例 #8
0
		private void attach_TeamMatches(TeamMatch entity)
		{
			this.SendPropertyChanging();
			entity.Team = this;
		}