public IImmutableList <ValidationResult> AddSurvey(SurveyDto surveyDto)
        {
            if (surveyDto.QuestionGroupsDtos == null)
            {
                Status.AddError("No question groups have been submitted with this survey.");
                return(Status.Errors);
            }

            if (string.IsNullOrWhiteSpace(surveyDto.Name))
            {
                Status.AddError("A name has not been provided for this survey.");
                return(Status.Errors);
            }

            var questionGroups = _questionMapper.Map(surveyDto.QuestionGroupsDtos, _context);
            var survey         = new Survey(surveyDto.Name, questionGroups);

            if (Status.HasErrors)
            {
                return(Status.Errors);
            }

            _context.Add(survey);
            _context.SaveChanges();
            return(null);
        }
Example #2
0
        public IImmutableList <ValidationResult> AddQuestionGroup(SurveyDto dto)
        {
            var survey = _context.Find <Survey>(dto.Id);

            if (survey == null)
            {
                Status.AddError($"Could not find Survey with an Id of {dto.Id}");
                return(Status.Errors);
            }

            var questionGroups = _questionMapper.Map(dto.QuestionGroupsDtos, _context);

            Status = survey.AddQuestionGroups(questionGroups, _context);
            if (Status.HasErrors)
            {
                return(Status.Errors);
            }
            _context.SaveChanges();
            return(null);
        }