Exemplo n.º 1
0
        public StandardGame[] StandardGamesFinished(UserContext context)
        {
            var id    = context.Authorize().Id.ToString();
            var games = context.Search <StandardGame>(
                expr => expr.Filter(
                    game => game.G("CurrentQuestion").Eq(null).And(game.G("User").Eq(id))), UserContext.ReadType.WithDocument);

            return(games);
        }
Exemplo n.º 2
0
        public StandardGame[] StandardGamesOngoing(UserContext context)
        {
            var id    = context.Authorize().Id.ToString();
            var games = context.Search <StandardGame>(
                expr => expr.Filter(
                    game => game.G("CurrentQuestion").Ne(null).And(game.G("User").Eq(id))), UserContext.ReadType.WithDocument);

            games.ToList().ForEach(d => d.Scrub());
            return(games);
        }
Exemplo n.º 3
0
        public DefaultResult <bool> RemoveAllStandardGames(UserContext context)
        {
            var user  = context.Authorize();
            var games = context.Search <StandardGame>(
                expr => expr.Filter(
                    game => game.G("User").Eq(user.Id.ToString())), UserContext.ReadType.Shallow);

            foreach (var standardGame in games)
            {
                context.Remove <StandardGame>(standardGame.Id);
            }
            return(new DefaultResult <bool>(true));
        }
Exemplo n.º 4
0
        public StandardGame StandardGame(UserContext context, Id id)
        {
            var user = context.Authorize();
            var game = context.Get <StandardGame>(id, UserContext.ReadType.Shallow);

            if (game.User.Id != user.Id)
            {
                return(null);
            }

            var ret = context.Get <StandardGame>(id);

            return(ret);
        }
Exemplo n.º 5
0
        public StandardGameResult AnswerStandard(UserContext context, Id gameId, int index)
        {
            var user        = context.Authorize();
            var tempContext = new UserContext("query{dummy{user{id} lives id completedQuestions{id year text} currentQuestion{id year text}}}");
            var game        = tempContext.Get <StandardGame>(gameId);

            if (user?.Id != game?.User.Id)
            {
                return(null);
            }

            var evaluated = game.EvaluateStandardGame(index);

            context.UpdateDefault(evaluated.Item1, game.Id);
            evaluated.Item1.Scrub();
            return(new StandardGameResult(evaluated.Item1, evaluated.Item2));
        }
Exemplo n.º 6
0
        public DefaultResult <User> SetUserName(UserContext context, string userName)
        {
            var  existingUser = context.Authorize(AuthMode.UserId);
            User newUser;

            if (existingUser == null)
            {
                newUser = new User(context.UserName, userName);
                context.AddDefault(newUser);
            }
            else
            {
                newUser = new User(existingUser.UserId, userName);
                context.UpdateDefault(newUser, existingUser.Id);
            }

            return(new DefaultResult <User>(newUser));
        }
Exemplo n.º 7
0
        public DefaultResult <StandardGame> StartNewStandardGame(UserContext context)
        {
            var user = context.Authorize();
            var seed = QuestionUtil.GetRandomQuestion();

            Question firstQuestion;

            while (true)
            {
                firstQuestion = QuestionUtil.GetRandomQuestion();
                if (firstQuestion.Id != seed.Id)
                {
                    break;
                }
            }

            var game = new StandardGame(firstQuestion, new[] { seed }, 3, user);

            context.AddDefault(game);

            game.Scrub();
            return(new DefaultResult <StandardGame>(game));
        }
Exemplo n.º 8
0
 public User User(UserContext context)
 {
     return(context.Authorize());
 }