Exemplo n.º 1
0
 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));
     }
 }
Exemplo n.º 2
0
        public ActionResult Create(int?parentId)
        {
            var model = new CategoryEditorModel
            {
                ParentId = parentId
            };

            PrepareEditor(model);

            return(View(model));
        }
Exemplo n.º 3
0
        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));
        }