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 })); }
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 })); }