private bool IsUserOwner(CreateProtestDto model)
        {
            var game = _playedGamesService.GetById(model.PlayedGameId);

            if (_teamService.IsUserOwner(model.AppUserId, game.HomeTeamId.Value) || _teamService.IsUserOwner(model.AppUserId, game.AwayTeamId.Value))
            {
                return(true);
            }
            return(false);
        }
        public IActionResult UpdateScore(MemberUpdatePlayedGameDto model)
        {
            if (ModelState.IsValid)
            {
                var loggedUserId = GetLoggedUser().Id;
                if (model.LoggedUserId != loggedUserId)
                {
                    return(Unauthorized());
                }

                var playedGame = _playedGamesService.GetById(model.Id);

                if (playedGame.IsFinished)
                {
                    throw new Exception("Game is finished.");
                }

                var winnerTeam = _playedGamesService.UpdateScore(playedGame, model.HomeTeamScore.Value, model.AwayTeamScore.Value, loggedUserId);
                if (playedGame.IsAwayTeamConfirmedResult && playedGame.IsHomeTeamConfirmedResult)
                {
                    _playedGamesService.AddWinnerToNextGame(playedGame, winnerTeam); // not yet!
                }
            }
            else
            {
                model = _mapper.Map <MemberUpdatePlayedGameDto>(_playedGamesService.GetAllById(model.Id));
                return(View(model));
            }
            return(RedirectToAction("Index", "Tournament", new { area = "", Id = model.PlayedGamesRound.TournamentId }));
        }
Exemple #3
0
 public IActionResult UpdateScore(UpdatePlayedGameDto model)
 {
     if (ModelState.IsValid)
     {
         var playedGame = _playedGamesService.GetById(model.Id);
         var winnerTeam = _playedGamesService.UpdateScore(playedGame, model.HomeTeamScore.Value, model.AwayTeamScore.Value);
         _playedGamesService.AddWinnerToNextGame(playedGame, winnerTeam);
     }
     else
     {
         model = _mapper.Map <UpdatePlayedGameDto>(_playedGamesService.GetAllById(model.Id));
         return(View(model));
     }
     return(RedirectToAction("Index", new { tournamentId = model.PlayedGamesRound.TournamentId }));
 }