public async Task <IActionResult> CreateProcess(Models.Process process) { db.Processes.Add(process); await db.SaveChangesAsync(); return(RedirectToAction("ViewProcceses")); }
public JsonResult saveToDB(string data, string myPlan) { var db = new DBModelEntities(); IList <Models.Process> procList = db.Processes.ToList(); IList <Models.Attribute> attribList = db.Attributes.ToList(); IList <Models.AttributeVariable> attribVarList = db.AttributeVariables.ToList(); string herp = data; string[] arr = herp.Split('|'); for (int i = 1; i < arr.Length; i++) { Plan plan = new Plan(); //If free text variable if (arr[i].Contains(":")) { string model = arr[i].Substring(0, arr[i].IndexOf(":")); Models.Attribute textAttrib = attribList.Single(x => x.Name == model); Models.Process textProc = procList.Single(x => x.ACode == textAttrib.Code); string selected = arr[i].Substring(arr[i].IndexOf(":") + 1); plan.ProcessID = textProc.ID; plan.PlanName = myPlan; //plan.Selected = arr[i]; plan.Selected = selected; db.Plans.Add(plan); db.SaveChanges(); } else { //Find attribVar where name == data[i] //AttributeVariable attribVar = attribVarList.Single(x => x.Name == "FreeText"); //try { AttributeVariable attribVar = attribVarList.Single(x => x.Name == arr[i]); //} //catch //{ //} //Find attrib containing attribVar Models.Attribute attrib = attribList.Single(x => x.AttributeVariables.Contains(attribVar)); //Find process with where acode == attrib.acode Models.Process proc = procList.Single(x => x.ACode == attrib.Code); plan.ProcessID = proc.ID; plan.PlanName = myPlan; plan.Selected = arr[i]; db.Plans.Add(plan); db.SaveChanges(); } } return(Json(true)); }
public ProcessViewModel(Models.Process process) { this.process = process; }