public async Task <IActionResult> CollectionDetails(long gameId, int regionId) { if (!this.User.Identity.IsAuthenticated) { return(this.Redirect("/Identity/Account/Login")); } HomePageGameViewModel viewModel = new HomePageGameViewModel(); var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); try { viewModel = await this.gamesService.GetModelByGameId(gameId, regionId, userId); } catch (System.Exception e) { this.ModelState.AddModelError("details", e.Message); } if (!this.ModelState.IsValid) { return(this.Redirect("DetailsError")); } return(this.View(viewModel)); }
public async Task <HomePageGameViewModel> GetModelByGameId(long gameId, int regionId, string userId) // More eficient.. { if (regionId < 0 || regionId > 10) { throw new ArgumentException("Region Id must be between 0 and 10!"); } var region = (RiotSharp.Misc.Region)regionId; var game = await this.Api.Match.GetMatchAsync(region, gameId); var dbGame = this.db.Games.FirstOrDefault(g => g.RiotGameId == game.GameId); if (dbGame == null) { throw new ArgumentException("Game with that Game Id does not exist in the database!"); } var isInUserCollection = this.db.UserGames.Any(ug => ug.UserId == userId && ug.GameId == dbGame.GameId); if (isInUserCollection == false && userId != "SharedGameUser") { throw new InvalidOperationException($"This user ({userId}) does not contain a game with id({gameId}) in his collection!"); } var viewModel = new HomePageGameViewModel { GameId = game.GameId, RegionId = regionId, BlueTeam = new TeamDTO { Players = await this.playersService.GetPlayersByParticipantsDto(game.ParticipantIdentities, game.Participants, 100), State = game.Teams[0].Win, DragonsSlain = game.Teams[0].DragonKills, BaronsSlain = game.Teams[0].BaronKills, TurretsDestroyed = game.Teams[0].TowerKills, TotalGold = this.teamsService.GetTotalGoldByPlayers(game.ParticipantIdentities, game.Participants, 100), }, RedTeam = new TeamDTO { Players = await this.playersService.GetPlayersByParticipantsDto(game.ParticipantIdentities, game.Participants, 200), State = game.Teams[1].Win, DragonsSlain = game.Teams[1].DragonKills, BaronsSlain = game.Teams[1].BaronKills, TurretsDestroyed = game.Teams[1].TowerKills, TotalGold = this.teamsService.GetTotalGoldByPlayers(game.ParticipantIdentities, game.Participants, 200), }, }; return(viewModel); }
public async Task <IActionResult> SharedGame(long gameId, int regionId) { HomePageGameViewModel viewModel = new HomePageGameViewModel(); try { viewModel = await this.gamesService.GetModelByGameId(gameId, regionId, "SharedGameUser"); } catch (System.Exception e) { this.ModelState.AddModelError("details", e.Message); } if (!this.ModelState.IsValid) { return(this.Redirect("DetailsError")); } return(this.View(viewModel)); }
public async Task <HomePageGameViewModel> GetModelByGameId(long gameId) // More eficient.. { var game = await api.Match.GetMatchAsync(region, gameId); var viewModel = new HomePageGameViewModel { GameId = game.GameId, BlueTeam = new TeamDTO { Players = this.playersService.GetPlayersByParticipantsDto(game.ParticipantIdentities, game.Participants, 100), State = game.Teams[0].Win }, RedTeam = new TeamDTO { Players = this.playersService.GetPlayersByParticipantsDto(game.ParticipantIdentities, game.Participants, 200), State = game.Teams[1].Win } }; return(viewModel); }