Esempio n. 1
0
 public string StorePermanentResults(PermanentResults permanentResults)
 {
     try
     {
         var pcollection = _database.GetCollection <PermanentResults>(nameof(PermanentResults));
         pcollection.InsertOne(permanentResults);
         return(permanentResults.PublicToken);
     }
     catch (Exception ex)
     {
         _log.Error(ex, ex.Message);
     }
     return("");
 }
Esempio n. 2
0
        public string UpdateRespondentQS(string token, long respondentId, QuestionnaireChoices passedQuestionnaire)
        {
            if (!_userValidation.ValidateToken(token))
            {
                throw new AddressAccessDeniedException();
            }
            _log.Information($"{GetCurrentMethod()} called.");
            try
            {
                //lock (_locker)
                {
                    var scope = _questionnaireRepository.FindQuestionnaireById(passedQuestionnaire.ScopeId);
                    scope.Passed++;
                    _questionnaireRepository.Upsert(scope);

                    var res = _outcomeComputer.ComputeOutcomes(passedQuestionnaire, scope);

                    var permanent = new PermanentResults
                    {
                        OutcomeHeader = scope.OutcomeHeader,
                        ScopeId       = passedQuestionnaire.ScopeId,
                        Outcomes      = res.ToList()
                    };

                    var permatoken = _respondentsRepository.StorePermanentResults(permanent);

                    var target = _respondentsRepository.FindById(respondentId);
                    target.Activity.Add(new ActivityData {
                        Code = ActivityCode.PassedQuestionaire, RelatedScopeId = passedQuestionnaire.ScopeId
                    });

                    var extended = new ExtendedQuestionnaireChoices
                    {
                        AnswerIds   = passedQuestionnaire.AnswerIds,
                        ScopeId     = passedQuestionnaire.ScopeId,
                        PublicToken = permatoken
                    };

                    target.AttendedQuestionnairies.Add(extended);
                    _respondentsRepository.Save(target);
                    return(permatoken);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex, ex.Message);
                return("");
            }
        }