public EditPlayedGameInfo GetInfoForEditingPlayedGame(int playedGameId, ApplicationUser currentUser)
        {
            var editPlayedGameInfo = _dataContext.GetQueryable <PlayedGame>()
                                     .Where(x => x.Id == playedGameId)
                                     .Select(x => new EditPlayedGameInfo
            {
                DatePlayed       = x.DatePlayed,
                GameDefinitionId = x.GameDefinitionId,
                Notes            = x.Notes,
                BoardGameGeekGameDefinitionId = x.GameDefinition.BoardGameGeekGameDefinitionId,
                GameDefinitionName            = x.GameDefinition.Name,
                PlayerRanks = x.PlayerGameResults.Select(y => new PlayerRankWithName
                {
                    PlayerId     = y.PlayerId,
                    PlayerName   = y.Player.Name,
                    GameRank     = y.GameRank,
                    PointsScored = y.PointsScored
                })
                              .OrderBy(y => y.GameRank)
                              .ThenBy(y => y.PlayerName)
                              .ToList()
            }).FirstOrDefault();

            if (editPlayedGameInfo == null)
            {
                throw new EntityDoesNotExistException <PlayedGame>(playedGameId);
            }

            var gameRanks = editPlayedGameInfo.PlayerRanks.Select(x => x.GameRank).ToList();

            editPlayedGameInfo.WinnerType = _winnerTypeCalculator.CalculateWinnerType(gameRanks);

            var playersModel = _playerRetriever.GetPlayersForEditingPlayedGame(playedGameId, currentUser);

            editPlayedGameInfo.OtherPlayers  = playersModel.OtherPlayers;
            editPlayedGameInfo.RecentPlayers = playersModel.RecentPlayers;
            editPlayedGameInfo.UserPlayer    = playersModel.UserPlayer;

            return(editPlayedGameInfo);
        }
Пример #2
0
        //TODO this should be in its own class or just in AutoMapperConfiguration
        public virtual PlayedGame TransformNewlyCompletedGameIntoPlayedGame(
            SaveableGameBase savedGame,
            int gamingGroupId,
            string applicationUserId,
            List <PlayerGameResult> playerGameResults)
        {
            var gameRanks  = playerGameResults.Select(x => x.GameRank).ToList();
            var winnerType = _winnerTypeCalculator.CalculateWinnerType(gameRanks);

            var numberOfPlayers = savedGame.PlayerRanks.Count;
            var playedGame      = new PlayedGame
            {
                GameDefinitionId           = savedGame.GameDefinitionId,
                NumberOfPlayers            = numberOfPlayers,
                WinnerType                 = winnerType,
                PlayerGameResults          = playerGameResults,
                DatePlayed                 = savedGame.DatePlayed,
                GamingGroupId              = gamingGroupId,
                Notes                      = savedGame.Notes,
                CreatedByApplicationUserId = applicationUserId
            };

            return(playedGame);
        }