/// <summary> /// 删除 /// </summary> /// <param name="category">类别实体</param> public virtual void DeleteCategory(Category category) { if (category == null) throw new ArgumentNullException("category"); _categoryRepository.Delete(category); }
/// <summary> /// 插入 /// </summary> /// <param name="category">类别实体</param> public virtual void InsertCategory(Category category) { if (category == null) throw new ArgumentNullException("category"); _categoryRepository.Insert(category); }
/// <summary> /// 类别面包屑格式-类别名称 /// </summary> /// <param name="category">类别</param> /// <param name="separator">分隔符号</param> /// <returns>面包屑格式</returns> public virtual string GetFormattedBreadCrumb(Category category, string separator = ">>") { if (category == null) throw new ArgumentNullException("category"); string result = string.Empty; var alreadyProcessedCategoryIds = new List<int>() { }; while (category != null && //not null !category.Deleted && //not deleted !alreadyProcessedCategoryIds.Contains(category.Id)) //prevent circular references { if (String.IsNullOrEmpty(result)) { result = category.Name; } else { result = string.Format("{0} {1} {2}", category.Name, separator, result); } alreadyProcessedCategoryIds.Add(category.Id); category = _categoryRepository.GetById(category.ParentId); } return result; }