public IImmutableList <ValidationResult> SaveCompletedQuestion(CompletedSurveyDto dto) { if (dto.Questions == null) { Status.AddError("No Questions have been submitted with this completed survey."); return(Status.Errors); } var completedSurvey = _context.Find <CompletedSurvey>(dto.CompletedSurveyId); if (completedSurvey == null) { Status.AddError($"Could not find Survey with an Id of {dto.CompletedSurveyId}"); return(Status.Errors); } var completedQuestions = _mapper.MapQuestionsFromDto(dto.Questions, _context); foreach (var question in completedQuestions) { Status = completedSurvey.AddQuestion(question, _context); } if (Status.HasErrors) { return(Status.Errors); } _context.SaveChanges(); return(null); }
public IImmutableList <ValidationResult> AddQuestion(SurveyDto surveyDto) { var survey = _context.Find <Survey>(surveyDto.Id); if (survey == null) { Status.AddError($"Could not find Survey with an Id of {surveyDto.Id}"); return(Status.Errors); } var questionGroup = _context.Find <QuestionGroup>(surveyDto.QuestionGroupId); if (questionGroup == null) { Status.AddError($"Could not find QuestionGroup with an Id of {surveyDto.QuestionGroupId}"); return(Status.Errors); } foreach (var question in surveyDto.QuestionsDtos) { if (question.Type == 0) { Status.AddError("A question has been submitted with an invalid question type."); return(Status.Errors); } if (string.IsNullOrWhiteSpace(question.Text)) { Status.AddError("A question has been submitted without any text."); return(Status.Errors); } } var questions = _questionMapper.Map(surveyDto.QuestionsDtos, _context); Status = survey.AddQuestions(questions, questionGroup, _context); if (Status.HasErrors) { return(Status.Errors); } _context.SaveChanges(); return(null); }
public IImmutableList <ValidationResult> RemoveSurvey(SurveyDto dto) { var survey = _context.Find <Survey>(dto.Id); if (survey == null) { Status.AddError($"A survey with the ID of {dto.Id} was not found."); return(Status.Errors); } Status = survey.RemoveSelf(_context); if (Status.HasErrors) { return(Status.Errors); } _context.SaveChanges(); return(null); }
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); }
public IImmutableList <ValidationResult> RenameSurvey(SurveyDto dto) { var survey = _context.Find <Survey>(dto.Id); if (survey == null) { Status.AddError($"A survey with the Id {dto.Id} does not exist."); return(Status.Errors); } if (string.IsNullOrWhiteSpace(dto.NewName)) { Status.AddError("No new name has been provided for this survey."); return(Status.Errors); } Status = survey.RenameSurvey(dto.NewName, _context); if (Status.HasErrors) { return(Status.Errors); } _context.SaveChanges(); return(null); }