コード例 #1
0
 ////             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();
     }
 }
コード例 #2
0
 public ActionResult Edit(ThemeListQuestionsVM ViewModel)
 {
     if (ModelState.IsValid)
     {
         ThemeServ.EditQuestion(ViewModel);
         return(RedirectToAction("Index"));
     }
     return(View(ViewModel));
 }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        public ActionResult Create(ThemeListQuestionsVM ViewModel)
        {
            //ModelState.Clear();
            if (ModelState.IsValid)
            {
                ThemeServ.CreateTheme(ViewModel);
                return(RedirectToAction("Index"));
            }

            return(View(ViewModel));
        }
コード例 #5
0
        //                      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();
            }
        }
コード例 #6
0
        // 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));
        }
コード例 #7
0
        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);
            }
        }