public ActionResult Enter(IEnumerable<Pick> picks) { int userID = CurrentUser.UserID; foreach (Pick pick in picks) { Game game = db.Games.Include("Week").Where(g => g.GameID == pick.GameID).FirstOrDefault(); if (game != null && game.Week.CutoffDate > Helpers.Now && game.GameDate > Helpers.Now) { Pick userPick = db.Picks.Where(p => p.UserID == userID && p.GameID == pick.GameID).FirstOrDefault(); if (userPick == null) userPick = new Pick(); userPick.PickDate = Helpers.Now; userPick.GameID = pick.GameID; userPick.UserID = userID; userPick.UserPick = pick.UserPick; if (pick.TotalPoints != 0) userPick.TotalPoints = pick.TotalPoints; if (userPick.PickID == 0) db.Picks.Add(userPick); } } db.SaveChanges(); return Redirect("~/"); }
public ActionResult Picks(int id, IEnumerable<Pick> picks) { foreach (Pick pick in picks) { Game game = db.Games.Include("HomeTeam").Include("VisitingTeam").Where(g => g.GameID == pick.GameID).First(); if (!game.Week.Completed) { Pick userPick = db.Picks.Where(p => p.UserID == pick.UserID && p.GameID == pick.GameID).FirstOrDefault(); if (userPick == null) userPick = new Pick(); userPick.PickDate = Helpers.Now; userPick.GameID = pick.GameID; userPick.UserID = pick.UserID; userPick.UserPick = pick.UserPick; if (pick.TotalPoints != 0) userPick.TotalPoints = pick.TotalPoints; if (userPick.PickID == 0) db.Picks.Add(userPick); } db.SaveChanges(); } db.Database.ExecuteSqlCommand("exec sp_updateRecords " + id.ToString()); return Redirect("~/Admin"); }