コード例 #1
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();
            }
        }
コード例 #2
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);
         }
     }
 }
コード例 #3
0
		private void detach_Matches(Match entity)
		{
			this.SendPropertyChanging();
			entity.Season = null;
		}
コード例 #4
0
		private void attach_Matches(Match entity)
		{
			this.SendPropertyChanging();
			entity.Season = this;
		}
コード例 #5
0
 partial void DeleteMatch(Match instance);
コード例 #6
0
 partial void UpdateMatch(Match instance);
コード例 #7
0
 partial void InsertMatch(Match instance);