Esempio n. 1
0
        /// <summary>
        /// Updates the color of the radruga. (for development only)
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public async Task UpdateRadrugaColor()
        {
            var users = await _userRepository.GetUsers(new QueryOptions <User>() { Expand = new List <string> {
                                                                                       "PersonQualities"
                                                                                   } });

            var rnd = new Random();

            foreach (var user in users)
            {
                if (!String.IsNullOrEmpty(user.RadrugaColor))
                {
                    if (!user.PersonQualitiesWithScores.AnyValues(pq => pq.PersonQualityId == GameConstants.PersonQuality.ActivityQualityId) &&
                        !user.PersonQualitiesWithScores.AnyValues(pq => pq.PersonQualityId == GameConstants.PersonQuality.CommunicationQualityId))
                    {
                        user.PersonQualitiesWithScores = user.PersonQualitiesWithScores ?? new List <PersonQualityIdWithScore>();
                        user.PersonQualitiesWithScores.Add(new PersonQualityIdWithScore()
                        {
                            PersonQualityId = GameConstants.PersonQuality.ActivityQualityId, Score = rnd.Next(-30, 30)
                        });
                        user.PersonQualitiesWithScores.Add(new PersonQualityIdWithScore()
                        {
                            PersonQualityId = GameConstants.PersonQuality.CommunicationQualityId, Score = rnd.Next(-30, 30)
                        });
                    }
                }

                RewardsCalculator.UpdateRadrugaColor(user, true);
                await _userRepository.UpdateUser(user);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     User has answered the question.
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <param name="questionsAnswers">The questions answers.</param>
        /// <returns>Task{OperationResult}.</returns>
        /// <exception cref="System.ArgumentNullException">Wrong input</exception>
        public async Task <ColorResult> AnswerQuestions(string userId, PersonQualityIdWithScore[] questionsAnswers)
        {
            //TODO check if user has already answered questions
            if (string.IsNullOrEmpty(userId) || questionsAnswers == null)
            {
                throw new ArgumentNullException(
                          string.IsNullOrEmpty(userId) ? "userId" : "questionsAnswers",
                          "Wrong input");
            }

            var user = await _userRepository.GetUser(userId);

            if (user == null)
            {
                return((ColorResult)OperationResult.NotFound);
            }

            RewardsCalculator.UpdateUserAfterAnsweringQuestion(questionsAnswers, user);
            await _assignmentService.AssignMissionSetLine(user);

            await RewardsCalculator.SetNewMissionSets(user, _missionRepository);

            RewardsCalculator.UpdateRadrugaColor(user, true);

            var userUpdateResult = await _userRepository.UpdateUser(user);

            return(userUpdateResult.Status == OperationResultStatus.Success
                       ? new ColorResult(user.RadrugaColor)
                       : (ColorResult)userUpdateResult);
        }