public async Task <OperationDataResult <AnswerViewModel> > GetAnswerByMicrotingUid(int microtingUid)
        {
            try
            {
                var core = await _coreHelper.GetCore();

                AnswerViewModel result;
                await using (var sdkContext = core.DbContextHelper.GetDbContext())
                {
                    var answersQueryable = AnswerHelper.GetAnswerQueryByMicrotingUid(microtingUid, sdkContext);

                    result = answersQueryable.FirstOrDefault();
                }

                if (result == null)
                {
                    return(new OperationDataResult <AnswerViewModel>(
                               false,
                               _localizationService.GetString("AnswerNotFound")));
                }

                if (result.AnswerValues == null)
                {
                    return(new OperationDataResult <AnswerViewModel>(
                               false,
                               _localizationService.GetString("AnswerValuesNotFound")));
                }

                return(new OperationDataResult <AnswerViewModel>(true, result));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationDataResult <AnswerViewModel>(false,
                                                                 _localizationService.GetString("ErrorWhileObtainingGetAnswer")));
            }
        }
Exemplo n.º 2
0
        public void Answer_Get()
        {
            var answer = AnswerHelper.GetAnswerQueryByMicrotingUid(MicrotingUid, DbContext).FirstOrDefault();

            Assert.NotNull(answer);
            Assert.AreEqual(answer.Id, _answerForTest.Id);
            Assert.AreEqual(answer.MicrotingUid, _answerForTest.MicrotingUid);
            for (var i = 0; i < _answerForTest.AnswerValues.Count; i++)
            {
                var answerValues        = answer.AnswerValues[i];
                var answerValuesForTest = _answerForTest.AnswerValues[i];
                Assert.AreEqual(answerValues.Id, answerValuesForTest.Id);
                Assert.AreEqual(answerValues.Value, answerValuesForTest.Value);
                for (var j = 0; j < answerValuesForTest.Translations.Count; j++)
                {
                    var translationsForTest = answerValuesForTest.Translations[j];
                    var translations        = answerValues.Translations[j];
                    Assert.AreEqual(translations.LanguageId, translationsForTest.LanguageId);
                    Assert.AreEqual(translations.LanguageName, translationsForTest.LanguageName);
                    Assert.AreEqual(translations.Value, translationsForTest.Value);
                }
            }
        }