コード例 #1
0
        public ActionResult Create(SeasonTable seasontable)
        {
            if (ModelState.IsValid)
            {
                db.SeasonTableSet.AddObject(seasontable);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.SeasonId = new SelectList(db.SeasonSet, "Id", "Name", seasontable.SeasonId);
            ViewBag.TeamId = new SelectList(db.TeamSet, "Id", "Name", seasontable.TeamId);
            return View(seasontable);
        }
コード例 #2
0
 private void UpdatePlacementInSeasonTable(Season season)
 {
     int i = 1;
     var lastSeasonTable = new SeasonTable();
     var seasonTableOrdered = db.SeasonTableSet.OrderBy("it.Points DESC");
     seasonTableOrdered = (ObjectQuery<SeasonTable>) seasonTableOrdered.Where(s => s.SeasonId == season.Id);
     foreach (SeasonTable currentSeasonTable in seasonTableOrdered)
     {
         currentSeasonTable.Placement = i;
         i++;
         if (lastSeasonTable.Id != 0)
         {
             CheckGoalDifference(lastSeasonTable, currentSeasonTable);
         }
         lastSeasonTable = currentSeasonTable;
     }
     db.SaveChanges();
 }
コード例 #3
0
        private IEnumerable<SeasonTable> CreateSeasonTableEntriesFromMatchesInSeason(Season season, IEnumerable<Match> matches)
        {
            var seasonTableEntries = new List<SeasonTable>();
            foreach (Match match in matches)
            {
                int homeTeamId = match.HomeTeamId;
                int awayTeamId = match.AwayTeamId;
                bool homeTeamExists = seasonTableEntries.Exists(t => t.TeamId == homeTeamId);
                bool awayTeamExists = seasonTableEntries.Exists(t => t.TeamId == awayTeamId);

                SeasonTable seasonTableEntry;
                if (!homeTeamExists)
                {
                    seasonTableEntry = new SeasonTable
                                           {
                                               SeasonId = season.Id,
                                               TeamId = match.TeamHome.Id,
                                               Placement = 0,
                                               Points = match.HomeGoals > match.AwayGoals ? 3 : 0,
                                               Victories = match.HomeGoals > match.AwayGoals ? 1 : 0,
                                               Defeats = match.HomeGoals < match.AwayGoals ? 1 : 0,
                                               GoalsScored = match.HomeGoals,
                                               GoalsLetIn = match.AwayGoals,
                                               GoalDifference = match.HomeGoals - match.AwayGoals,
                                               MatchesPlayed = 1
                                           };

                    seasonTableEntries.Add(seasonTableEntry);
                }
                else
                {
                    seasonTableEntry = seasonTableEntries.Single(s => s.TeamId == match.HomeTeamId);
                    if (match.HomeGoals > match.AwayGoals)
                    {
                        seasonTableEntry.Points += 3;
                        seasonTableEntry.Victories += 1;
                    }
                    else
                    {
                        seasonTableEntry.Defeats += 1;
                    }

                    seasonTableEntry.GoalsScored += match.HomeGoals;
                    seasonTableEntry.GoalsLetIn += match.AwayGoals;
                    seasonTableEntry.GoalDifference = seasonTableEntry.GoalsScored - seasonTableEntry.GoalsLetIn;
                    seasonTableEntry.MatchesPlayed += 1;
                }

                if (!awayTeamExists)
                {
                    seasonTableEntry = new SeasonTable
                                           {
                                               SeasonId = season.Id,
                                               TeamId = match.TeamAway.Id,
                                               Placement = 0,
                                               Points = match.AwayGoals > match.HomeGoals ? 3 : 0,
                                               Victories = match.AwayGoals > match.HomeGoals ? 1 : 0,
                                               Defeats = match.AwayGoals < match.HomeGoals ? 1 : 0,
                                               GoalsScored = match.AwayGoals,
                                               GoalsLetIn = match.HomeGoals,
                                               GoalDifference = match.AwayGoals - match.HomeGoals,
                                               MatchesPlayed = 1
                                           };

                    seasonTableEntries.Add(seasonTableEntry);
                }
                else
                {
                    seasonTableEntry = seasonTableEntries.Single(s => s.TeamId == match.AwayTeamId);
                    if (match.AwayGoals > match.HomeGoals)
                    {
                        seasonTableEntry.Points += 3;
                        seasonTableEntry.Victories += 1;
                    }
                    else
                    {
                        seasonTableEntry.Defeats += 1;
                    }

                    seasonTableEntry.GoalsScored += match.AwayGoals;
                    seasonTableEntry.GoalsLetIn += match.HomeGoals;
                    seasonTableEntry.GoalDifference = seasonTableEntry.GoalsScored - seasonTableEntry.GoalsLetIn;
                    seasonTableEntry.MatchesPlayed += 1;
                }
            }
            return seasonTableEntries;
        }
コード例 #4
0
 private void CheckGoalDifference(SeasonTable lastSeasonTable, SeasonTable currentSeasonTable)
 {
     if (lastSeasonTable.Points == currentSeasonTable.Points)
     {
         if (lastSeasonTable.GoalDifference < currentSeasonTable.GoalDifference)
         {
             lastSeasonTable.Placement += 1;
             currentSeasonTable.Placement -= 1;
         }
     }
 }
コード例 #5
0
 public ActionResult Edit(SeasonTable seasontable)
 {
     if (ModelState.IsValid)
     {
         db.SeasonTableSet.Attach(seasontable);
         db.ObjectStateManager.ChangeObjectState(seasontable, EntityState.Modified);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.SeasonId = new SelectList(db.SeasonSet, "Id", "Name", seasontable.SeasonId);
     ViewBag.TeamId = new SelectList(db.TeamSet, "Id", "Name", seasontable.TeamId);
     return View(seasontable);
 }
コード例 #6
0
 /// <summary>
 /// Deprecated Method for adding a new object to the SeasonTableSet EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSeasonTableSet(SeasonTable seasonTable)
 {
     base.AddObject("SeasonTableSet", seasonTable);
 }
コード例 #7
0
 /// <summary>
 /// Create a new SeasonTable object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="seasonId">Initial value of the SeasonId property.</param>
 /// <param name="teamId">Initial value of the TeamId property.</param>
 /// <param name="placement">Initial value of the Placement property.</param>
 /// <param name="points">Initial value of the Points property.</param>
 /// <param name="goalsScored">Initial value of the GoalsScored property.</param>
 /// <param name="goalsLetIn">Initial value of the GoalsLetIn property.</param>
 /// <param name="matchesPlayed">Initial value of the MatchesPlayed property.</param>
 public static SeasonTable CreateSeasonTable(global::System.Int32 id, global::System.Int32 seasonId, global::System.Int32 teamId, global::System.Int32 placement, global::System.Int32 points, global::System.Int32 goalsScored, global::System.Int32 goalsLetIn, global::System.Int32 matchesPlayed)
 {
     SeasonTable seasonTable = new SeasonTable();
     seasonTable.Id = id;
     seasonTable.SeasonId = seasonId;
     seasonTable.TeamId = teamId;
     seasonTable.Placement = placement;
     seasonTable.Points = points;
     seasonTable.GoalsScored = goalsScored;
     seasonTable.GoalsLetIn = goalsLetIn;
     seasonTable.MatchesPlayed = matchesPlayed;
     return seasonTable;
 }