Пример #1
0
        public IActionResult GetUser()
        {
            var x    = new UserGetter(userDataAccess);
            var user = x.GetUserFromClaims(HttpContext);

            return(Ok(new
            {
                username = user.Name,
                userID = user.UserID
            }));
        }
Пример #2
0
        public IActionResult GetFreeGames()
        {
            var         user       = userGetter.GetUserFromClaims(HttpContext);
            User        gamePlayer = null;
            List <Game> games      = new List <Game>();

            if (user != null)
            {
                gamePlayer = userDataAccess.GetUser(user.UserID);
                games      = gameDataAccess.GetGames(g => g.Winner == null && g.IsFinished != true && (
                                                         g.PlayerBlackID == null || g.PlayerWhiteID == null ||
                                                         g.PlayerWhiteID == gamePlayer.ID || g.PlayerBlackID == gamePlayer.ID));
            }
            else if (user == null)
            {
                games = gameDataAccess.GetGames(g => g.PlayerBlackID == null || g.PlayerWhiteID == null);
            }

            var gamesModels = games.Select(g => ViewModelMapper.MapGameToPresentation(g));

            return(Ok(gamesModels));
        }