public void SaveSeason(int id, int sWe, DateTime ssD, int dId)
 {
     Season season;
     //
     if (dId > 0)
     {
         // get the current season, and set it inactive, and inactivate all the games associated with
         // the season
         var dDeason = _ctx.Seasons.Where(s => s.Id == dId).Single();
         dDeason.IsCurrent = false;
         _ctx.SaveChanges();
     }
     //
     if (id > 0)
     {
         season = _ctx.Seasons.Where(s => s.Id == id).SingleOrDefault();
         season.IsCurrent = dId > 0 || (season.IsCurrent && dId == 0);
         season.NumberOfWeeks = sWe;
         season.StartDate = ssD;
         season.EndDate = ssD.AddDays(sWe * 7);
     }
     else
     {
         season = new Season()
         {
             EndDate = ssD.AddDays(sWe * 7),
             StartDate = ssD,
             NumberOfWeeks = sWe,
             IsCurrent = true
         };
         _ctx.AddToSeasons(season);
     }
     //
     _ctx.SaveChanges();
     //
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Seasons EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSeasons(Season season)
 {
     base.AddObject("Seasons", season);
 }
 public SeasonViewModel GetCurrentSeason(string userId)
 {
     // setup auto-mapper
     AutoMapperConfiguration.Setup(_ctx);
     var season = new Season();
     if (_ctx.Seasons.Count(s => s.IsCurrent) == 1)
         season = _ctx.Seasons.Where(s => s.IsCurrent).Single();
     // map to a view model
     var svm = Mapper.Map<Season, SeasonViewModel>(season);
     svm.Leaderboard = GetLeaderboard();
     // get the season's score thus far
     var winningPicks =
         _ctx.Picks.Where(p => p.Game.Season.IsCurrent && p.IsWinner.HasValue && p.IsWinner.Value && p.UserId == userId).ToList();
     var winningPsPicks = _ctx.PlayoffSuperbowlPicks.Where(p => p.IsWinner && p.Season.IsCurrent && p.UserId == userId).ToList();
     // we need to make sure there are winning picks before we try to sum them
     svm.SeasonPointTotal = winningPicks.Count > 0 ? winningPicks.Sum(p => p.PointTotal) : 0;
     svm.SeasonPointTotal += winningPsPicks.Count > 0 ? winningPsPicks.Sum(p => p.PointTotal) : 0;
     //
     return svm;
 }
 /// <summary>
 /// Create a new Season object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="startDate">Initial value of the StartDate property.</param>
 /// <param name="endDate">Initial value of the EndDate property.</param>
 /// <param name="isCurrent">Initial value of the IsCurrent property.</param>
 /// <param name="numberOfWeeks">Initial value of the NumberOfWeeks property.</param>
 public static Season CreateSeason(global::System.Int32 id, global::System.DateTime startDate, global::System.DateTime endDate, global::System.Boolean isCurrent, global::System.Int32 numberOfWeeks)
 {
     Season season = new Season();
     season.Id = id;
     season.StartDate = startDate;
     season.EndDate = endDate;
     season.IsCurrent = isCurrent;
     season.NumberOfWeeks = numberOfWeeks;
     return season;
 }