public ActionResult Create(int? parentId)
        {
            var model = new CategoryEditorModel
            {
                ParentId = parentId
            };

            PrepareEditor(model);

            return View(model);
        }
 private void PrepareEditor(CategoryEditorModel model)
 {
     ViewBag.ParentPath = "None".Localize();
     if (model.ParentId != null)
     {
         var parent = CategoryTree.Get(CurrentInstance.Name).Find(model.ParentId.Value);
         ViewBag.ParentPath = String.Join(" >> ", parent.PathFromRoot().Select(c => c.Name));
     }
 }
        public ActionResult Save(CategoryEditorModel model, string @return)
        {
            Category category = null;

            if (model.Id > 0)
            {
                category = _categoryService.Find(model.Id);
            }
            else
            {
                category = new Category();
            }

            category.Name = model.Name;
            category.Description = model.Description;
            category.Photo = model.Photo;

            if (model.ParentId != null)
            {
                category.Parent = _categoryService.Find(model.ParentId.Value);
            }

            category.CustomFields.Clear();

            foreach (var field in model.CustomFields)
            {
                category.CustomFields.Add(new CategoryCustomField(field.Name, field.Value));
            }

            if (model.Id > 0)
            {
                _categoryService.Update(category);
            }
            else
            {
                _categoryService.Create(category);
            }

            return AjaxForm().RedirectTo(@return);
        }