public ActionResult CreateBaselineAssessment(CreateBaselineAssessmentViewModel m) { //If input is valid if (ModelState.IsValid) { //Create the assessment in the database var assessmentType = new PX_Model.Assessment_Type(); assessmentType.Name = m.Name; assessmentType.Trial_Id = m.TrialId; assessmentType.Description = m.Description; _db.Assessment_Type.Add(assessmentType); _db.SaveChanges(); //Create the question in the database linked with the assessment foreach (var question in m.Questions) { if (question.AddToQuestion) { var assessmentTypeQuestion = new PX_Model.Assessment_Type_Question(); assessmentTypeQuestion.Question = question.Question; assessmentTypeQuestion.Question_Type = question.Type; assessmentTypeQuestion.Assessment_Type_Id = assessmentType.Id; _db.Assessment_Type_Question.Add(assessmentTypeQuestion); _db.SaveChanges(); if (question.Type != PX_Model.Assessment_Type_Question.TYPE_TEXT) { //Save the options in the database foreach (var option in question.Options) { var opt = new PX_Model.Assessment_Type_Option(); opt.Opt = option; opt.Assessment_Type_Question_Id = assessmentTypeQuestion.Id; _db.Assessment_Type_Option.Add(opt); } _db.SaveChanges(); } } } //Go to admin dashboard once succeeded return View("Index"); } //Get the trial list again and show the form again if there was an error m.Trials = _db.Trials.OrderBy(t => t.Name).ToArray(); return View(m); }
//Show the form to create baseline assessment public ActionResult CreateBaselineAssessment() { var m = new CreateBaselineAssessmentViewModel(); m.Trials = _db.Trials.OrderBy(t => t.Name).ToArray(); return View(m); }