Inheritance: ILocalizable
        public CategoryEditorModel(Category category, bool children = false)
            : this()
        {
            this.Id = category.Id;
            this.Name = category.Name;
            this.Photo = category.Photo;
            this.Description = category.Description;
            this.Published = category.Published;
            //
            if (category.Parent != null)
            {
                this.ParentId = category.Parent.Id.ToString();
                SetParentCrumble(category.Parent);
            }
            //
            if (children && category.Children != null)
            {
                foreach (var item in category.Children)
                {
                    this.Children.Add(new CategoryEditorModel(item, children));
                }
            }
            this.CustomFields = new List<CategoryCustomFieldModel>();
            if (category.CustomFields != null && category.CustomFields.Count > 0)
            {
                foreach (var cf in category.CustomFields)
                {
                    var cfm = new CategoryCustomFieldModel();
                    cfm.Name = cf.Name;
                    cfm.Value = cf.Value;

                    this.CustomFields.Add(cfm);
                }
            }
        }
Exemple #2
0
 public CategoryRowModel(Category category, bool parent = false)
     : this()
 {
     this.Id = category.Id;
     this.Name = category.Name;
     this.Photo = category.Photo;
     this.Description = category.Description;
     this.ChildrenCount = category.Children == null ? 0 : category.Children.Count;
     if (parent && category.Parent != null)
     {
         this.Parent = new CategoryRowModel(category.Parent, parent);
     }
 }
Exemple #3
0
 public CategoryDeleted(Category category)
 {
     CategoryId = category.Id;
     CategoryName = category.Name;
 }
        public void UpdateTo(Category category)
        {
            category.Id = this.Id;
            category.Name = (this.Name ?? string.Empty).Trim();
            category.Photo = (this.Photo ?? string.Empty).Trim();
            category.Description = (this.Description ?? string.Empty).Trim();
            category.Published = this.Published;
            //
            //if (!string.IsNullOrEmpty(this.ParentId)) {
            //    category.Parent = new Category() { Id = int.Parse(this.ParentId) };
            //}
            //
            if (this.Children != null)
            {
                category.Children = new List<Category>();
                foreach (var item in this.Children)
                {
                    var obj = new Category();
                    item.UpdateTo(obj);
                    category.Children.Add(obj);
                }
            }
            if (this.CustomFields != null && this.CustomFields.Count > 0)
            {
                category.CustomFields = new List<CategoryCustomField>();
                foreach (var cfm in this.CustomFields)
                {
                    var cf = new CategoryCustomField();
                    cf.CategoryId = this.Id;
                    cf.Name = cfm.Name;
                    cf.Value = cfm.Value;

                    category.CustomFields.Add(cf);
                }
            }
        }
 public void SetParentCrumble(Category parent)
 {
     var p = parent;
     List<string> crumbles = new List<string>();
     while (p != null)
     {
         crumbles.Insert(0, p.Name);
         p = p.Parent;
     }
     this.ParentCrumble = string.Join(">>", crumbles.ToArray());
 }
Exemple #6
0
 public CategoryModel(Category category)
 {
     Id = category.Id;
     Name = category.Name;
     Description = category.Description;
 }
Exemple #7
0
 public CategoryUpdated(Category category)
 {
     CategoryId = category.Id;
 }
        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);
        }
Exemple #9
0
 public CategoryCreated(Category category)
 {
     CategoryId = category.Id;
 }
Exemple #10
0
        static CategoryTreeNode BuildEntry(Category category, IEnumerable<Category> all)
        {
            var entry = new CategoryTreeNode
            {
                Id = category.Id,
                Name = category.Name,
                Description = category.Description,
                Photo = category.Photo,
                CustomFields = category.CustomFields.ToDictionary(f => f.Name, f => f.Value)
            };

            foreach (var child in all.Where(c => c.Parent != null && c.Parent.Id == category.Id))
            {
                var childEntry = BuildEntry(child, all);
                entry.Children.Add(childEntry);
                childEntry.Parent = entry;
            }

            return entry;
        }
Exemple #11
0
 public void Update(Category category)
 {
     _categoryRepository.Update(category);
     Event.Raise(new CategoryUpdated(category), _instance);
 }
Exemple #12
0
 public void Delete(Category category)
 {
     _categoryRepository.Delete(category);
     Event.Raise(new CategoryDeleted(category), _instance);
 }
Exemple #13
0
 public void Create(Category category)
 {
     _categoryRepository.Insert(category);
     Event.Raise(new CategoryCreated(category), _instance);
 }
 static bool IsParent(int id, Category child)
 {
     var ret = false;
     while (child.Parent != null) {
         if (child.Parent.Id == id) {
             ret = true;
             break;
         }
         child = child.Parent;
     }
     return ret;
 }