public async Task <Entity.Survey.Question> AddQuestionToSurvey(int surveyId, Entity.Survey.Question question) { var survey = await GetSurveyById(surveyId); if (survey != null) { question.Id = ++LastQuestionId; if (survey.Questions == null) { survey.Questions = new List <Entity.Survey.Question>(); } survey.Questions.Add(question); } return(question); }
public async Task <bool> UpdateQuestion(int surveyId, Entity.Survey.Question question) { var survey = await GetSurveyById(surveyId); if (survey.Questions != null && survey.Questions.Any()) { var ques = survey.Questions.FirstOrDefault(q => q.Id == question.Id); if (ques != null) { ques.Text = question.Text; ques.UpdatedDateTime = question.UpdatedDateTime; ques.Answers = question.Answers; return(true); } } return(false); }
public async Task <Model.Output.Question> CreateSurveyQuestion(Model.Input.Question question) { var survey = await _repository.GetSurveyById(question.SurveyId); if (survey != null) { var newQuestion = new Entity.Survey.Question { Text = question.Text, CreatedDateTime = DateTime.Now, UpdatedDateTime = DateTime.Now, Answers = new List <Entity.Survey.Answer> { new Entity.Survey.Answer { Text = question.YesAnswerText, Value = true }, new Entity.Survey.Answer { Text = question.NoAnswerText, Value = false } } }; newQuestion = await _repository.AddQuestionToSurvey(question.SurveyId, newQuestion); var result = new Model.Output.Question { QuestionId = newQuestion.Id, SurveyId = question.SurveyId, Text = newQuestion.Text, Answers = newQuestion.Answers.Select(a => new Model.Output.Answer { Text = a.Text, Value = a.Value }) }; return(result); } return(null); }