public bool Add(Data.ApplicationDbContext context) { try { var survey = new Data.Survey { Title = this.Title }; context.Surveys.Add(survey); context.SaveChanges(); if (this.Childs != null) { foreach (var child in this.Childs) { child.Add(context); } } return(true); } catch { return(false); } }
private void BuildSurvey(Data.Survey survey, Question question) { if (!string.IsNullOrWhiteSpace(Request.Form[question.Id.ToString()])) { switch (question.Type) { case 0: case 1: var ans = new SurveyAnswer() { AnswerId = Convert.ToInt32(Request.Form[question.Id.ToString()]) }; survey.SurveyAnswers.Add(ans); break; case 2: string[] values = Request.Form[question.Id.ToString()].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var val in values) { var a = new SurveyAnswer() { AnswerId = Convert.ToInt32(val) }; survey.SurveyAnswers.Add(a); } break; case 3: var comment = new SurveyComment() { QuestionId = question.Id, Comments = Request.Form[question.Id.ToString()] }; survey.SurveyComments.Add(comment); break; } } }