Exemplo n.º 1
0
 public ActionResult Create(Question question)
 {
     if (ModelState.IsValid)
       {
     questionRepository.InsertOrUpdate(question);
     questionRepository.Save();
     return RedirectToAction("SurveyQuestions", new { surveyId = question.SurveyId });
       }
       PopulateViewBag(question.SurveyId);
       return View(question);
 }
Exemplo n.º 2
0
 public ActionResult Create(int surveyId)
 {
     var q = new Question()
         {
           Options = new List<QuestionOption>()
                       {
                         new QuestionOption(), new QuestionOption(), new QuestionOption()
                       },
           SurveyId = surveyId
         };
       PopulateViewBag(surveyId);
       return View(q);
 }
Exemplo n.º 3
0
 public void InsertOrUpdate(Question question)
 {
     PurgeEmptyOptions(question);
       if (question.Id == default(int))
       {
     // New entity
     context.Questions.Add(question);
       }
       else
       {
     // Existing entity
     DeleteDestroyedOptions(question);
     SetQuestionId(question.Options, question.Id);
     context.SetEntityStateForChildren(question.Options);
     context.Entry(question).State = EntityState.Modified;
       }
 }
Exemplo n.º 4
0
 private void DeleteDestroyedOptions(Question question)
 {
     context.ProcessDestroyableChildren(question.Options);
       var destroyed = question.Options.Where(x => x.Destroy && x.Id > 0).ToList();
       foreach (var questionOption in destroyed)
       {
     question.Options.Remove(questionOption);
       }
 }
Exemplo n.º 5
0
 private static void PurgeEmptyOptions(Question question)
 {
     if(question.Options!=null)
       {
     var emptyOptions = question.Options.Where(option => string.IsNullOrWhiteSpace(option.OptionText)).ToList();
     foreach (var emptyOption in emptyOptions)
     {
       question.Options.Remove(emptyOption);
     }
       }
 }