public ActionResult Create([Bind(Include = "position,lastName,fName,team,pointsScored,passingTDs,passingYDs,passingINTs,rushingTDs,rushingYDs,receivingTDs,receivingYDs,receptions,fumblesLost,gamesPlayed")] V_PlayersWithStats v_PlayersWithStats) { if (ModelState.IsValid) { db.V_PlayersWithStats.Add(v_PlayersWithStats); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(v_PlayersWithStats)); }
public ActionResult Create([Bind(Include = "playerId,fName,lastName,position,team")] player player) { if (ModelState.IsValid) { db.players.Add(player); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(player)); }
public ActionResult Create([Bind(Include = "pointsScored,gamesPlayed,Player_playerId,rushingTDs,rushingYDs,fumblesLost,receptions,receivingTDs,receivingYDs,passingYDs,passingINTs,passingTDs,Year,Week,statsID")] stat stat) { if (ModelState.IsValid) { db.stats.Add(stat); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Player_playerId = new SelectList(db.players, "playerId", "fName", stat.Player_playerId); return(View(stat)); }
public ActionResult DeleteConfirmed(int id) { using (PlayersEntities players = new PlayersEntities()) { Player player = players.Players.Find(id); var games = player.Games.ToList(); var roles = player.PlayerRoles.ToList(); foreach (var game in games) { player.Games.Remove(game); } var role = player.PlayerRoles.FirstOrDefault(r1 => r1.PlayerId == player.Id); if (role.Role.Id == 2) { players.PlayerRoles.Remove(role); } players.Players.Remove(player); players.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Edit([Bind(Include = "Id,Username,Password,Email,Win_Rate,IpAddress,Status")] Player player) { using (PlayersEntities players = new PlayersEntities()) { if (ModelState.IsValid) { players.Entry(player).State = EntityState.Modified; players.SaveChanges(); return(RedirectToAction("Index")); } return(View(player)); } }
public ActionResult Create([Bind(Include = "Id,Username,Password,Email,Win,Lose,IpAddress,Status")] Player player) { using (PlayersEntities players = new PlayersEntities()) { if (ModelState.IsValid) { players.Players.Add(player); players.SaveChanges(); return(RedirectToAction("Index")); } return(View(player)); } }
public ActionResult Edit([Bind(Include = "Id,Username,Password,Email,Win_Rate,IpAddress,Status")] Player player) { using (PlayersEntities players = new PlayersEntities()) { if (ModelState.IsValid) { players.Entry(player).State = EntityState.Modified; players.SaveChanges(); } FormsAuthentication.SignOut(); return(RedirectToAction("Login", "Account")); } }
public ActionResult MyStats() { int won = 0; int lost = 0; int total_games = 0; decimal percentage; using (PlayersEntities players = new PlayersEntities()) { Player p = players.Players.FirstOrDefault(r => r.Username == User.Identity.Name); var games = p.Games.ToList(); foreach (var g in games) { if (g.WinnerId == p.Id) { won++; } else { lost++; } } if (won > 0) { percentage = (decimal)won / games.Count * 100; } else { percentage = 0; } p.Win_Rate = percentage; ViewBag.ratio = percentage; ViewBag.won = won; ViewBag.lost = lost; ViewBag.total = games.Count; players.SaveChanges(); return(View(games)); } }
public ActionResult Register([Bind(Include = "Username,Password,Email")] Player player) { if (ModelState.IsValid) { using (PlayersEntities players = new PlayersEntities()) { Player p = players.Players.FirstOrDefault(r => r.Username == player.Username || r.Email == player.Email); if (p != null) { ViewBag.Error = "Player with that username or mail already exist"; return(View(player)); } else { if (player.Password.Length < 6) { ViewBag.Pass = "******"; return(View(player)); } else { var role = new PlayerRole { PlayerId = player.Id, RoleId = 2 }; player.PlayerRoles.Add(role); player.Win_Rate = (decimal)0.0; player.Status = "Offline"; players.Players.Add(player); players.SaveChanges(); return(RedirectToAction("Login", "Account")); } } } } return(View(player)); }
public ActionResult TopPlayers() { int wins = 0; using (PlayersEntities players = new PlayersEntities()) { var player = players.Players.ToList(); var game = players.Games.ToList(); foreach (var pl in player) { foreach (var g in game) { if (pl.Id == g.WinnerId) { wins++; } } if (pl.Games.Count > 0) { pl.Win_Rate = (decimal)wins / pl.Games.Count * 100; wins = 0; } else { pl.Win_Rate = (decimal)0.0; wins = 0; } players.SaveChanges(); } var p = players.Players.OrderBy(r => r.Games.Count).OrderByDescending(r => r.Win_Rate).Take(3).ToList(); return(View(p)); } }