public async Task <IActionResult> PostAnalyticsAnonymously([FromBody] AnalyticsViewModel analytics)
        {
            try
            {
                Assessment assessment = _assessmentViewModelFactory.Create(analytics.Assessment);
                assessment.AssessmentCreatorId = null;
                assessment = await _analyticsBusiness.SaveAssessment(assessment);

                List <AnalyticQuestionAnswer> questions = (_questionViewModelFactory.Create(analytics.QuestionAnswers.AsQueryable())).ToList();
                questions.ForEach(x => x.AssessmentId = assessment.Assessment_Id);
                questions.Where(x => x.AnswerText == null).ToList().ForEach(x => x.AnswerText = "U");



                await _analyticsBusiness.SaveAnalyticQuestions(questions);

                return(Ok(new { message = "Analytics data saved" }));
            }
            catch (Exception ex)
            {
                return(BadRequest($"Analytic information was not saved: {ex.Message}"));
            }
        }
예제 #2
0
        public async Task <ResultDto <Domain.Contact.Contact> > CreateAsync(CreateUpdateContactDto dto, CancellationToken cancellationToken)
        {
            var validationResult = _createUpdateContactDtoValidator.Validate(dto);
            var result           = new ResultDto <Domain.Contact.Contact>(validationResult);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning("Contact creation validation failed: {message}", validationResult.ToString());
                return(result);
            }

            var contact = _contactFactory.Create(dto);

            await _contactRepository.AddAsync(contact);

            await _contactRepository.UnitOfWork.SaveChangesAsync(true, cancellationToken);

            result.AddData(contact);
            return(result);
        }