//public ActionResult UpdatePick(int LeagueId, int SeasonId, int Week, int TeamId) public ActionResult UpdatePick(UpdatePick pick) { //if (Session["PlayerId"] == null) return RedirectToAction("Index", "Home"); int playerId = Convert.ToInt32(Session["PlayerId"]); using (NFLLeagueEntities nfl = new NFLLeagueEntities()) { if (nfl.PlayerSelections.Count(ps => ps.PlayerId == playerId && ps.LeagueId == pick.LeagueId && ps.SeasonId == pick.SeasonId && ps.SelectedTeamId == pick.TeamId) > 0) { nfl.PlayerSelections.Remove(nfl.PlayerSelections.SingleOrDefault(ps => ps.PlayerId == playerId && ps.LeagueId == pick.LeagueId && ps.SeasonId == pick.SeasonId && ps.SelectedTeamId == pick.TeamId)); nfl.SaveChanges(); } var playerSelection = nfl.PlayerSelections.Where(ps => ps.PlayerId == playerId && ps.LeagueId == pick.LeagueId && ps.SeasonId == pick.SeasonId && ps.Week == pick.Week).FirstOrDefault(); if (playerSelection != null) { playerSelection.SelectedTeamId = pick.TeamId; } else { playerSelection = new PlayerSelection() { LeagueId = pick.LeagueId, SeasonId = pick.SeasonId, PlayerId = playerId, Week = pick.Week, SelectedTeamId = pick.TeamId }; nfl.PlayerSelections.Add(playerSelection); } nfl.SaveChanges(); } return(RedirectToAction("WeeklyMatchups", new { pick.LeagueId, pick.SeasonId, pick.Week })); }
public ActionResult Register(LeaguesRegisterViewModel vm) { using (NFLLeagueEntities nfl = new NFLLeagueEntities()) { if (nfl.Leagues.Where(l => l.Name == vm.LeagueName).Count() > 0) { ViewBag.Message = "League Already Exists"; return(Register()); } else { NFL.League league = new NFL.League(); league.Name = vm.LeagueName; league.Notes = vm.LeagueNotes; league.CommissionerPlayerID = vm.CommissionerPlayerId; league.Created = vm.LeagueRegistrationDate; nfl.Leagues.Add(league); nfl.SaveChanges(); foreach (var invitee in vm.Invitees) { //nfl.LeagueInvitations.Add(new LeagueInvitation() { LeagueId = league.ID, PlayerName = invitee.Name, PlayerEmail = invitee.Email, Date = DateTime.Now }); } nfl.SaveChanges(); } } return(View(vm)); }