コード例 #1
0
        public ActionResult UpdateQuestion(QuestionDBTable Obj)
        {
            DBEntities DBContext     = new DBEntities();
            int        QuestionIDKey = Convert.ToInt32(TempData["QuestionIDKey"]);

            Obj.UserName = User.Identity.Name;
            if (!ModelState.IsValid)
            {
                return(View("EditQuestion", Obj));
            }
            try
            {
                QuestionDBTable Temp = DBContext.QuestionDBTables.SingleOrDefault(x => x.ID == QuestionIDKey);
                if (Temp != null)
                {
                    Temp.QuestionString         = Obj.QuestionString;
                    DBContext.Entry(Temp).State = EntityState.Modified;
                    DBContext.SaveChanges();
                }
            }
            catch
            {
                return(View("EditQuestion", Obj));
            }
            return(RedirectToAction("Index", "Home"));
        }
コード例 #2
0
        public ActionResult DeleteQuestion(int id)
        {
            DBEntities      DBContext = new DBEntities();
            QuestionDBTable Temp      = DBContext.QuestionDBTables.FirstOrDefault(x => x.ID == id);

            if (Temp != null)
            {
                DBContext.QuestionDBTables.Remove(Temp);
                DBContext.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            return(HttpNotFound());
        }
コード例 #3
0
        public ActionResult CreateQuestion(QuestionDBTable Obj)
        {
            DBEntities DBContext = new DBEntities();

            if (!ModelState.IsValid)
            {
                return(View("GetQuestion", Obj));
            }
            try
            {
                Obj.UserName = User.Identity.Name;
                DBContext.QuestionDBTables.Add(Obj);
                DBContext.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            catch
            {
                return(View("GetQuestion", Obj));
            }
        }
コード例 #4
0
        public ActionResult Index(int id)
        {
            DBEntities DBContext = new DBEntities();
            IEnumerable <AnswerDBTable> Selected         = DBContext.AnswerDBTables.Where(x => x.QuestionID == id);
            List <AnswerDBTable>        SelectedAnswers  = Selected.ToList();
            QuestionDBTable             QuestionSelected = DBContext.QuestionDBTables.First(x => x.ID == id);

            QuestionAnswerViewModel QAViewModel = new QuestionAnswerViewModel
            {
                Question = QuestionSelected,
                Answers  = SelectedAnswers
            };


            if (SelectedAnswers.Count() == 0)
            {
                return(HttpNotFound());
            }
            return(View(QAViewModel));
        }