コード例 #1
0
        public ActionResult AddQuestion(AddQuestionViewModels questionModel)
        {
            var question     = new Question();
            var questionAttr = new QuestionAttribute();
            var QuestionId   = 0;

            question.Label       = questionModel.Label;
            question.Description = questionModel.Description;
            question.ControlId   = questionModel.ControlId;

            if (ModelState.IsValid)
            {
                question.UpdatedDate = DateTime.Now;
                db.questions.Add(question);
                db.SaveChanges();
                QuestionId = question.Id;
            }

            foreach (var item in questionModel.QuestionAttributes)
            {
                questionAttr.Name       = item.Name;
                questionAttr.Value      = item.Value;
                questionAttr.QuestionId = QuestionId;
                if (ModelState.IsValid)
                {
                    questionAttr.UpdatedDate = DateTime.Now;
                    db.questionAttributes.Add(questionAttr);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
            //return View(questionModel);
        }
コード例 #2
0
 public ActionResult AddControl(QuestionControl questionControl)
 {
     if (ModelState.IsValid)
     {
         questionControl.UpdatedDate = DateTime.Now;
         db.questionControls.Add(questionControl);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(questionControl));
 }
コード例 #3
0
        //save changes
        public bool SaveChanges()
        {
            try
            {
                return(_context.SaveChanges() > 0);
            }
            catch (Exception ex)
            {
                //Logger.GetLogger().Error(ex);

                throw new Exception("Save Entity Exception:", ex);
            }
        }