public ActionResult Edit(long?content_id, long block_id, long?content_root, long?content_template) { ViewBag.domain_id = CurrentUser.user_domain; ViewBag.content_id = content_id; ViewBag.block_id = block_id; ViewBag.content_root = content_root; using (BlockRepository block_repository = new BlockRepository()) { using (ContentRepository content_repository = new ContentRepository()) { using (TemplateRepository template_repository = new TemplateRepository()) { ViewBag.block = block_repository.GetByID(block_id); string allow_templates = string.Empty; if (content_root.HasValue) { dynamic root_item = content_repository.GetByID(content_root.Value); dynamic root_template = template_repository.GetByID(root_item.content_template); allow_templates = root_template.template_allow_subpartitions && root_item.content_block == block_id ? root_template.template_templates : string.Empty; } if (content_id.HasValue) { ViewBag.item = content_repository.GetByID(content_id.Value); } ViewBag.templates = template_repository.GetByIDs(string.IsNullOrWhiteSpace(allow_templates) ? ViewBag.block.block_templates : allow_templates); } } } if (ViewBag.templates.Count > 0) { ViewBag.current_template = ViewBag.templates[0]; foreach (var template in ViewBag.templates) { if (content_template.HasValue) { if (content_template.Value == template.template_id) { ViewBag.current_template = template; break; } } else if (ViewBag.item != null && template.template_id == ViewBag.item.content_template) { ViewBag.current_template = template; break; } } using (ViewRepository view_repository = new ViewRepository()) { ViewBag.content_views = view_repository.GetByIDs(ViewBag.current_template.template_views); } using (FieldRepository field_repository = new FieldRepository()) { ViewBag.fields = field_repository.GetByIDs(ViewBag.current_template.template_fields); } } return(View()); }