/// <summary> /// 修改文章 /// </summary> /// <param name="id">文章Id</param> /// <param name="name">标题</param> /// <param name="content">内容</param> /// <param name="tags">标签集</param> /// <param name="isIssue">是否发布</param> /// <param name="categoryId">分类Id</param> public void ModifyArticle(Guid id, string name, string content, List <string> tags, bool isIssue, Guid categoryId) { Article article = this._unitOfWork.Resolve <Article>(id); ArticleCategory category = this._unitOfWork.Resolve <ArticleCategory>(categoryId); if (category == null) { throw new InvalidOperationException("操作失败 , 文章分类Id不存在 !"); } // article.ArticleCategory.Articles.Remove(article); article.Modify(name, content, tags, isIssue, category); if (categoryId != article.ArticleCategory.Id) { category.AddArticle(article); this._unitOfWork.RegisterSave(category); } this._unitOfWork.RegisterSave(category); this._unitOfWork.Commit(); }
/// <summary> /// 添加文章 /// </summary> /// <param name="name">标题</param> /// <param name="content">内容</param> /// <param name="author">作者</param> /// <param name="authorId">作者Id</param> /// <param name="tags">标签集</param> /// <param name="isIssue">是否发布</param> /// <param name="categoryId">分类Id</param> /// <param name="sourceId">原文Id</param> /// <param name="packId">关联套餐Id</param> /// <param name="spaceId">关联套餐空间Id</param> public void AddArticle(string name, string content, string author, Guid authorId, List <string> tags, bool isIssue, Guid categoryId, Guid?sourceId, Guid?packId, Guid?spaceId) { if (sourceId == null && packId != null) { throw new InvalidOperationException("操作失败 , 原文章Id不可为空 !"); } if (sourceId != null && packId == null) { throw new InvalidOperationException("操作失败 , 关联套餐Id不可为空 !"); } ArticleCategory category = this._unitOfWork.Resolve <ArticleCategory>(categoryId); if (category == null) { throw new InvalidOperationException("操作失败 , 文章分类Id不存在 !"); } Article article = new Article(name, content, author, authorId, tags, isIssue, category, sourceId, packId, spaceId); category.AddArticle(article); this._unitOfWork.RegisterSave(category); this._unitOfWork.UnitedCommit(); }