public ActionResult AddAspect(BaroAspect aspect) { aspect.parent_id = (aspect.parent_id == 0) ? null : aspect.parent_id; if (aspect.parent_id == null) // Als node geen parent heeft is het een head aspect { aspect.is_head_aspect = 1; } _db.BaroAspects.InsertOnSubmit(aspect); _db.SubmitChanges(); // Haal de tree op BaroTreeViewWrapper viewModel = _db.BaroTemplates.Where(r => r.id == aspect.baro_template_id) .Select(r => new BaroTreeViewWrapper { Template = r, HeadAspect = r.BaroAspects.Where(d => d.is_head_aspect == 1 && d.parent_id == null || d.parent_id == 0).ToList() }).FirstOrDefault(); string treeHtml = RazorViewToString.RenderRazorViewToString(this, "_BaroTreePartial", viewModel); ViewBag.parent_id = aspect.parent_id; string selectHtml = RazorViewToString.RenderRazorViewToString(this, "_BaroSelectParents", viewModel); return(Json(new { status = "success", html_tree = treeHtml, html_select = selectHtml }, JsonRequestBehavior.AllowGet)); }
public ActionResult AddAspect(BaroAspect aspect) { aspect.parent_id = (aspect.parent_id == 0) ? null : aspect.parent_id; if (aspect.parent_id == null) // Als node geen parent heeft is het een head aspect { aspect.is_head_aspect = 1; } _db.BaroAspects.InsertOnSubmit(aspect); _db.SubmitChanges(); // Haal de tree op BaroTreeViewWrapper viewModel = _db.BaroTemplates.Where(r => r.id == aspect.baro_template_id) .Select(r => new BaroTreeViewWrapper { Template = r, HeadAspect = r.BaroAspects.Where(d => d.is_head_aspect == 1 && d.parent_id == null || d.parent_id == 0).ToList() }).FirstOrDefault(); string treeHtml = RazorViewToString.RenderRazorViewToString(this, "_BaroTreePartial", viewModel); ViewBag.parent_id = aspect.parent_id; string selectHtml = RazorViewToString.RenderRazorViewToString(this, "_BaroSelectParents", viewModel); return Json(new { status = "success", html_tree = treeHtml, html_select = selectHtml}, JsonRequestBehavior.AllowGet); }