Пример #1
0
        public async Task <IActionResult> SubmitTrainingMove(string id, string trainingSessionId, string origin, string destination, string promotion = null)
        {
            PuzzleTrainingSession session  = puzzleTrainingSessionRepository.Get(trainingSessionId);
            SubmittedMoveResponse response = session.ApplyMove(origin, destination, promotion);

            return(await JsonAfterMove(response, session));
        }
Пример #2
0
        public IActionResult SubmitTrainingMove(string id, string trainingSessionId, string origin, string destination, string promotion = null)
        {
            PuzzleTrainingSession session  = puzzleTrainingSessionRepository.Get(trainingSessionId);
            SubmittedMoveResponse response = session.ApplyMove(origin, destination, promotion);
            dynamic jsonResp = new ExpandoObject();

            if (response.Correct == 1 || response.Correct == -1)
            {
                int?loggedInUser = loginHandler.LoggedInUserId(HttpContext);
                if (loggedInUser.HasValue)
                {
                    ratingUpdater.AdjustRating(loggedInUser.Value, session.Current.ID, response.Correct == 1, session.CurrentPuzzleStartedUtc.Value, session.CurrentPuzzleEndedUtc.Value, session.Current.Variant);
                }
                jsonResp.rating = (int)session.Current.Rating.Value;
            }
            jsonResp.success = response.Success;
            jsonResp.correct = response.Correct;
            jsonResp.check   = response.Check;
            if (response.Error != null)
            {
                jsonResp.error = response.Error;
            }
            if (response.FEN != null)
            {
                jsonResp.fen = response.FEN;
            }
            if (response.ExplanationSafe != null)
            {
                jsonResp.explanation = response.ExplanationSafe;
            }
            if (response.Play != null)
            {
                jsonResp.play               = response.Play;
                jsonResp.fenAfterPlay       = response.FenAfterPlay;
                jsonResp.checkAfterAutoMove = response.CheckAfterAutoMove;
            }
            if (response.Moves != null)
            {
                jsonResp.dests = moveCollectionTransformer.GetChessgroundDestsForMoveCollection(response.Moves);
            }
            if (response.ReplayFENs != null)
            {
                jsonResp.replayFens   = response.ReplayFENs;
                jsonResp.replayChecks = response.ReplayChecks;
                jsonResp.replayMoves  = response.ReplayMoves;
            }
            return(Json(jsonResp));
        }