Пример #1
0
        public async Task <IGameChallenge> ChallengeGame(string language, int boardId, string challenger, string challenged)
        {
            if (boardId == 0)
            {
                var b = await GetDefaultBoard();

                boardId = b.Id;
            }

            var lexicon = await lexiconService.GetDictionary(language);

            if (lexicon == null)
            {
                return(null);
            }
            var board = await GetBoard(boardId);

            if (board == null)
            {
                return(null);
            }

            var q = gameQueueService.QueueChallenge(lexicon.Language, board.Id, challenger, challenged);

            return(new GameChallenge {
                Id = q.Id, Language = q.Language, BoardId = q.BoardId, Origin = q.Player1, Destination = q.Player2
            });
        }
Пример #2
0
        public async Task <IActionResult> GetWord(string language, string word)
        {
            string accessToken = await HttpContext.GetToken();

            var session = await sessionService.GetSession(accessToken);

            if (session == null)
            {
                return(Unauthorized(new { message = "Session expired. Please login again." }));
            }
            try
            {
                var lexicon = await lexiconService.GetDictionary(language);

                if (lexicon == null)
                {
                    return(NoContent());
                }

                var result = await lexiconService.GetWordInfo(lexicon.Language, word);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                await log.ErrorAsync("Error in wordRepository.GetDictionary()", ex);

                return(BadRequest(new { title = ex.GetType().ToString(), details = ex.StackTrace, message = ex.Message }));
            }
        }
Пример #3
0
        public async Task <IActionResult> QueueGame([FromBody] QueueGameRequest request)
        {
            string accessToken = await HttpContext.GetToken();

            var session = await sessionService.GetSession(accessToken);

            if (session == null)
            {
                return(Unauthorized(new { message = "Session expired. Please login again." }));
            }

            try
            {
                if (request.BoardId == 0)
                {
                    var b = await GetDefaultBoard();

                    request.BoardId = b.Id;
                }

                // Validate language and board
                var lexicon = await lexiconService.GetDictionary(request.Language);

                if (lexicon == null)
                {
                    return(null);
                }
                var board = await GetBoard(request.BoardId);

                if (board == null)
                {
                    return(null);
                }

                var queue = gameQueueService.QueueGame(lexicon.Language, board.Id, session.UserId);

                return(Ok(queue));
            }
            catch (Exception ex)
            {
                await log.ErrorAsync("Error in QueueGame()", ex);

                return(BadRequest(new { title = ex.GetType().ToString(), details = ex.StackTrace, message = ex.Message }));
            }
        }