//命令部分 #region # 添加文章分类 —— void AddArticleCategory(string name,int sort); /// <summary> /// 添加文章分类 /// </summary> /// <param name="name">名称</param> /// <param name="sort">排序</param> public ArticleCategoryInfo AddArticleCategory(string name, int sort) { if (this._repMediator.ArticleCategoryRepository.Exist(name)) { throw new InvalidOperationException("操作失败 , 文章分类名称重复 !"); } ArticleCategory category = new ArticleCategory(name, sort); this._unitOfWork.RegisterAdd(category); this._unitOfWork.Commit(); return(category.ToDTO()); }
/// <summary> /// 修改文章分类 /// </summary> /// <param name="id">分类Id</param> /// <param name="name">名称</param> /// <param name="sort">排序</param> public ArticleCategoryInfo ModifyArticleCategory(Guid id, string name, int sort) { ArticleCategory category = this._unitOfWork.Resolve <ArticleCategory>(id); ArticleCategory checkName = this._repMediator.ArticleCategoryRepository.GetByName(name); if (checkName != null && checkName.Id != id && checkName.Name == name) { throw new InvalidOperationException("操作失败 , 文章分类名称重复 !"); } category.Modify(name, sort); this._unitOfWork.RegisterSave(category); this._unitOfWork.Commit(); return(category.ToDTO()); }