//// Add | Save | Create \\ public void CreateTheme(ThemeListQuestionsVM ViewModel) { using (var db = new QuestionnaireDbContext()) { ViewModel.Theme.Questions = db.QuestionsDb.Where(question => ViewModel.CheckedQuestionIDs.Contains(question.QuestionID)).Include(y => y.Answers).ToList(); db.ThemesDb.Add(ViewModel.Theme); db.SaveChanges(); } }
public ActionResult Edit(ThemeListQuestionsVM ViewModel) { if (ModelState.IsValid) { ThemeServ.EditQuestion(ViewModel); return(RedirectToAction("Index")); } return(View(ViewModel)); }
public ThemeListQuestionsVM GetThemeVM(int?Id) { using (var db = new QuestionnaireDbContext()) { ThemeListQuestionsVM ViewModel = new ThemeListQuestionsVM(); ViewModel.Theme = db.ThemesDb.Include(x => x.Questions).Where(x => x.ThemeID == Id).FirstOrDefault(); return(ViewModel); } }
public ActionResult Create(ThemeListQuestionsVM ViewModel) { //ModelState.Clear(); if (ModelState.IsValid) { ThemeServ.CreateTheme(ViewModel); return(RedirectToAction("Index")); } return(View(ViewModel)); }
// Edit \\ public void EditQuestion(ThemeListQuestionsVM ViewModel) { using (var db = new QuestionnaireDbContext()) { Theme TempTheme = db.ThemesDb.Where(x => x.ThemeID == ViewModel.Theme.ThemeID).Include(y => y.Questions).FirstOrDefault(); TempTheme.Questions = db.QuestionsDb.Where(x => ViewModel.CheckedQuestionIDs.Contains(x.QuestionID)).Include(y => y.Answers).ToList(); db.Entry(TempTheme).State = EntityState.Modified; db.SaveChanges(); } }
// GET: Theme/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ThemeListQuestionsVM ViewModel = ThemeServ.GetThemeVM(id); ViewModel.Questions = QuestionServ.GetQuestions(); if (ViewModel == null) { return(HttpNotFound()); } return(View(ViewModel)); }
public ThemeListQuestionsVM GetThemesVM() { using (var db = new QuestionnaireDbContext()) { ThemeListQuestionsVM ViewModel = new ThemeListQuestionsVM(); //Get All Questions var questionlist = db.QuestionsDb.Include(y => y.Answers).ToList(); ViewModel.Questions = questionlist; Debug.WriteLine("QuestionCount :" + questionlist.Count); Debug.WriteLine("QuestionCountViewModel :" + ViewModel.Questions.Count); return(ViewModel); } }