public void SetupNewUserMidSeason(string userId)
 {
     // get the standard picks for the weeks prior
     var sPicks = _ctx.StandardPicks.Where(p => p.Game.GameDateTime < DateTime.Now && p.Active != null && p.Active.Value && p.Game.Season.IsCurrent).ToList();
     var sspPicks = _ctx.StandardPlayoffSuperbowlPicks.Where(p => p.Active != null && p.Active.Value && p.Season.IsCurrent).ToList();
     foreach (var sp in sPicks)
     {
         var pick = new Pick()
                        {
                            Game = sp.Game,
                            PointTotal = sp.PointTotal,
                            Team_Id = sp.Team_Id,
                            UpdateBy = "new_user_add",
                            UpdateDate = DateTime.Now,
                            UserId = userId,
                            IsWinner = sp.IsWinner
                        };
         // add the new pick to the context
         _ctx.AddToPicks(pick);
     }
     // playoff
     var season = _ctx.Seasons.Where(s => s.IsCurrent).SingleOrDefault();
     foreach (var sp in sspPicks)
     {
         var pick = new PlayoffSuperbowlPick()
                        {
                            IsPlayoff = sp.IsPlayoff,
                            IsSuperbowl = sp.IsSuperbowl,
                            Week = sp.Week,
                            PointTotal = sp.PointTotal,
                            UserId = userId,
                            Season = season,
                            Team_Id = sp.Team_Id
                        };
         // add to context
         _ctx.AddToPlayoffSuperbowlPicks(pick);
     }
     // save
     _ctx.SaveChanges();
 }
 /// <summary>
 /// Create a new Pick object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="game_Id">Initial value of the Game_Id property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="pointTotal">Initial value of the PointTotal property.</param>
 public static Pick CreatePick(global::System.Int32 id, global::System.Int32 game_Id, global::System.String userId, global::System.Int32 pointTotal)
 {
     Pick pick = new Pick();
     pick.Id = id;
     pick.Game_Id = game_Id;
     pick.UserId = userId;
     pick.PointTotal = pointTotal;
     return pick;
 }
        public void SavePick(MyPredictViewModel vm, string userId)
        {
            // do we have any picks for this week?
            foreach (var pvm in vm.MyPicks)
            {
                var p = _ctx.Picks.Where(pick => pick.Game.Id == pvm.Game.Id && pick.UserId == userId).SingleOrDefault();
                if (p != null && p.Team_Id > 0 && p.Game != null && p.Game.GameDateTime >= DateTime.Now)
                {
                    p.Game.Id = pvm.Game.Id;
                    p.PointTotal = pvm.PointTotal;
                    p.UserId = userId;
                    p.Team_Id = pvm.Team.Id;
                    p.UserId = userId;
                }
                else if (p == null)
                {
                    var game = _ctx.Games.Where(g => g.Id == pvm.Game.Id).SingleOrDefault();
                    if (game != null && pvm.Team != null && game.GameDateTime >= DateTime.Now)
                    {
                        var newPick = new Pick()
                                          {
                                              Game_Id = pvm.Game.Id,
                                              PointTotal = pvm.PointTotal,
                                              Team_Id = pvm.Team.Id,
                                              UserId = userId
                                          };
                        _ctx.AddToPicks(newPick);
                    }
                    else if (game != null && pvm.Team != null)
                    {
                        var newPick = new Pick()
                                          {
                                              Game_Id = pvm.Game.Id,
                                              PointTotal = 0,
                                              Team_Id = game.HomeTeam_Id,
                                              UserId = userId
                                          };
                        _ctx.AddToPicks(newPick);
                    }
                    //
                }
            }

            // save changes
            _ctx.SaveChanges();
            //
            if (vm.MyPlayoffPicks.Count > 0)
            {
                var pPicks = _ctx.PlayoffSuperbowlPicks.GetCurrentWeekPlayoffPicks(vm.CurrentWeek, userId).ToList();
                var delPicks = from p in pPicks
                               where !(from ps in vm.MyPlayoffPicks select ps.Team.Id).ToList().Contains(p.Team_Id)
                               select p;

                foreach (var playoffSuperbowlPick in delPicks)
                {
                    _ctx.PlayoffSuperbowlPicks.DeleteObject(playoffSuperbowlPick);
                }

                var addPicks = from p in vm.MyPlayoffPicks
                               where !(from ps in pPicks select ps.Team_Id).ToList().Contains(p.Team.Id)
                               select p;
                foreach (var superbowlPlayoffPickViewModel in addPicks)
                {
                    _ctx.AddToPlayoffSuperbowlPicks(new PlayoffSuperbowlPick()
                    {
                        IsPlayoff = true,
                        IsSuperbowl = false,
                        Team_Id = superbowlPlayoffPickViewModel.Team.Id,
                        PointTotal =
                            (vm.TheSeason.NumberOfWeeks - vm.CurrentWeek) + 1,
                        Season_Id = vm.TheSeason.Id,
                        UserId = userId,
                        Week = vm.CurrentWeek,
                        IsWinner = false
                    });
                }

                //
                _ctx.SaveChanges();
            }

            if (vm.MySuperbowlPicks.Count > 0)
            {
                var sPicks = _ctx.PlayoffSuperbowlPicks.GetCurrentWeekSuperbowlPicks(vm.CurrentWeek, userId).ToList();
                var delPicks = from p in sPicks
                               where!(from ps in vm.MySuperbowlPicks select ps.Team.Id).Contains(p.Team_Id)
                               select p;
                foreach (var playoffSuperbowlPick in delPicks)
                {
                    _ctx.PlayoffSuperbowlPicks.DeleteObject(playoffSuperbowlPick);
                }

                var addPicks = from p in vm.MySuperbowlPicks
                               where !(from ps in sPicks select ps.Team_Id).Contains(p.Team.Id)
                               select p;

                foreach (var superbowlPlayoffPickViewModel in addPicks)
                {
                    _ctx.AddToPlayoffSuperbowlPicks(new PlayoffSuperbowlPick()
                    {
                        IsPlayoff = false,
                        IsSuperbowl = true,
                        Team_Id = superbowlPlayoffPickViewModel.Team.Id,
                        PointTotal =
                            ((vm.TheSeason.NumberOfWeeks - vm.CurrentWeek) + 1)*2,
                        Season_Id = vm.TheSeason.Id,
                        UserId = userId,
                        Week = vm.CurrentWeek,
                        IsWinner = false
                    });
                }
                // save changes
                _ctx.SaveChanges();
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Picks EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPicks(Pick pick)
 {
     base.AddObject("Picks", pick);
 }