public ActionResult Monstars() { Team team = CSharpDbDAL.GetTeam(MONSTAR_OWNER_ID); List <Player> players = team.Players.ToList(); return(View(players)); }
public ActionResult Search() { AspNetUser currentUser = ORM.AspNetUsers.Single(user => user.Email == User.Identity.Name); Team currentUserTeam = CSharpDbDAL.GetTeam(currentUser.Id); return(View(currentUserTeam.Players)); }
public ActionResult Simulate() { Team monstars = CSharpDbDAL.GetTeam(MONSTAR_OWNER_ID); AspNetUser currentUser = ORM.AspNetUsers.Single(user => user.Email == User.Identity.Name); Team current = CSharpDbDAL.GetTeam(currentUser.Id); double monstarsSum = monstars.Players.Sum(player => player.Rating); double currentSum = current.Players.Sum(player => player.Rating); string result; if (currentSum > monstarsSum) { result = "You won!"; } else if (currentSum < monstarsSum) { result = "You lost!"; } else { result = "You tied..."; } TempData["result"] = new BattleResult(result); return(RedirectToAction("Battle")); }
public ActionResult Index() { // create their team AspNetUser currentUser = ORM.AspNetUsers.SingleOrDefault(u => u.Email == User.Identity.Name); if (currentUser != null) { Team currentUserTeam = CSharpDbDAL.GetTeam(currentUser.Id); if (currentUserTeam == null) { currentUserTeam = new Team() { Name = $"Team {currentUser.Email.Split('@')[0]}", OwnerId = currentUser.Id, Location = "Earth" }; if (!CSharpDbDAL.AddTeam(currentUserTeam)) { Console.WriteLine("Failed to add team"); } } } return(View()); }
public ActionResult TeamManagement() { AspNetUser currentUser = CSharpDbDAL.GetContextUser(User.Identity.Name); Team team = CSharpDbDAL.GetTeam(currentUser.Id); return(View(team)); }
public ActionResult AddPlayer(string playerId) { AspNetUser currentUser = ORM.AspNetUsers.Single(user => user.Email == User.Identity.Name); Team currentUserTeam = CSharpDbDAL.GetTeam(currentUser.Id); if (currentUserTeam.Players.Count >= 5) { TempData["Message"] = "Only 5 players allowed."; return(RedirectToAction("TeamManagement")); } Player alreadyExistingPlayer = currentUserTeam.Players.SingleOrDefault(p => p.Id == playerId); if (alreadyExistingPlayer != null) { TempData["Message"] = $"{alreadyExistingPlayer.Name} already belongs to team."; return(RedirectToAction("TeamManagement")); } JObject data = CsharpJamApi.GetSportPlayerId(playerId); JArray playerDataArray = (JArray)data["players"]; JObject playerData = (JObject)playerDataArray[0]; UserPlayer userPlayer = new UserPlayer(playerData) { Team = currentUserTeam }; Player player = new Player() { Id = userPlayer.Id, TeamId = userPlayer.TeamId, Name = userPlayer.Name, Skill = userPlayer.Skill, Agility = userPlayer.Agility, Strength = userPlayer.Strength, Endurance = userPlayer.Endurance, Aggression = userPlayer.Aggression, Humor = userPlayer.Humor, TeamWork = userPlayer.TeamWork, Rating = userPlayer.Rating, Height = userPlayer.Height, Weight = userPlayer.Weight, Description = userPlayer.Description, PictureUrl = userPlayer.PictureUrl, Team = userPlayer.Team }; CSharpDbDAL.AddPlayers(player); TempData["Message"] = $"{player.Name} added to team."; return(RedirectToAction("TeamManagement")); }