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); }
public ActionResult AddControl(QuestionControl questionControl) { if (ModelState.IsValid) { questionControl.UpdatedDate = DateTime.Now; db.questionControls.Add(questionControl); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(questionControl)); }
//save changes public bool SaveChanges() { try { return(_context.SaveChanges() > 0); } catch (Exception ex) { //Logger.GetLogger().Error(ex); throw new Exception("Save Entity Exception:", ex); } }