Ejemplo n.º 1
0
        /// <summary>
        ///     This is to get score by level and update information of memorizing user word pairs
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="levelMetricQuery"></param>
        /// <returns></returns>
        public async Task <LevelMetricQueryResult> SetResultsAsync(int userId, LevelMetricQuery levelMetricQuery)
        {
            // set sore;
            LevelMetricQueryResult levelMetricQueryResult = gameScoreService.GetLevelScore(levelMetricQuery.ToLevelResult());

            // save score to storage
            await gameScoreService.PostScoreAsync(userId, levelMetricQueryResult).ConfigureAwait(false);

            // Calculate word metric;
            IKnowledgeQualifier knowledgeQualifier = new CardGameKnowledge(levelMetricQuery);
            // update words pairs license in store
            await knowledgeUpdateService.UpdateKnowledge(userId, knowledgeQualifier).ConfigureAwait(false);

            return(levelMetricQueryResult);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostScore(LevelResult levelResult)
        {
            int authorizedId = User.GetUserId();
            // calculate score
            LevelMetricQueryResult answer = gameScoreService.GetLevelScore(levelResult);

            if (levelResult.LevelId < 0)
            {
                return(Ok(answer));
            }

            // save score to user level
            try
            {
                await gameScoreService.PostScoreAsync(authorizedId, answer);
            }
            catch (ArgumentNullException e)
            {
                return(BadRequest(e.Message));
            }

            return(Ok(answer));
        }