Exemple #1
0
        /// <summary>
        /// Returns ViewModel used to display information about logged-in user (if any)
        /// </summary>
        /// <returns></returns>
        public PlayerSingleViewModel GetSignedPlayer()
        {
            if (CurrentSignedPlayer.PlayerId == 0)
            {
                throw new InvalidOperationException("No signed in player");
            }

            var player   = this.context.Players.Find(CurrentSignedPlayer.PlayerId);
            var PlayerVM = new PlayerSingleViewModel()
            {
                Id         = player.Id,
                UserName   = player.UserName,
                FirstName  = player.FirstName,
                LastName   = player.LastName,
                IsBanned   = !(player.BeingBannedOn == null),
                IsOptedOut = !(player.PlayerOptedOutOn == null)
            };


            return(PlayerVM);
        }
Exemple #2
0
        /// <summary>
        /// Returns ViewModel used to display detail information about user by given id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public PlayerSingleExpandedViewModel GetDetailedPlayer(int id)
        {
            Player playerContext = context.Players.Find(id);

            if (playerContext == null)
            {
                throw new IndexOutOfRangeException("Player[index] - indexOutOfRange");
            }

            ICollection <GameSingleViewModel> games = new List <GameSingleViewModel>();

            List <Scoreboard> certainPlayerBestGames = context.Scoreboards
                                                       .Where(x => x.PlayerId == id && x.Score > 0).OrderByDescending(x => x.Score).ToList();

            foreach (var sb in certainPlayerBestGames)
            {
                if (context.Games.Find(sb.GameId).RemovedOn == null)
                {
                    games.Add(new GameSingleViewModel()
                    {
                        Name  = context.Games.Find(sb.GameId).Name,
                        Score = sb.Score,
                        Id    = sb.GameId
                    });
                }
            }



            var player = new PlayerSingleViewModel()
            {
                Id                    = playerContext.Id,
                FirstName             = playerContext.FirstName,
                LastName              = playerContext.LastName,
                UserName              = playerContext.UserName,
                AdditionalInformation = playerContext.AdditionalInformation,
            };

            int score = 0;

            foreach (var sb in context.Scoreboards.Where(x => x.PlayerId == id))
            {
                if (context.Games.Find(sb.GameId).RemovedOn == null)
                {
                    score += sb.Score;
                }
            }

            player.Score = score;
            var detailPlayer = new PlayerSingleExpandedViewModel()
            {
                Player = player,
                Games  = games,
                Age    = playerContext.Age
            };

            if (playerContext.BeingBannedOn == null)
            {
                detailPlayer.IsBanned = false;
            }
            else
            {
                detailPlayer.IsBanned             = true;
                detailPlayer.ReasonForBeingBanned = playerContext.ReasonForBeingBanned;
            }

            if (playerContext.PlayerOptedOutOn == null)
            {
                detailPlayer.IsOptedOut = false;
            }
            else
            {
                detailPlayer.IsOptedOut = true;
            }

            detailPlayer.Player.LoggedInId = CurrentSignedPlayer.PlayerId;

            return(detailPlayer);
        }