/// <summary> /// 添加Blog,会自动修正Blog的数据,新增blogId /// </summary> /// <param name="blog"></param> /// <param name="tags"></param> /// <returns></returns> public void AddBlog(Blog blog, IList <Tag> tags, BlogTagsApplication blogTagsApplication, TagApplication tagApplication) { //先调用ValidateAndCorrectSubmit验证更合理 blog.BlogId = string.IsNullOrWhiteSpace(blog.BName) ? FileCommon.CreateFileNameByTime() : blog.BName; blog.Date = DateTime.Now; IList <BlogTags> blogTags = blogTagsApplication.UpdateBlogTags(blog, tags, tagApplication); Add(blog); if (!Commit()) { throw new Exception("新增Blog异常"); } //新增BlogTags完毕,新增Blog blogTagsApplication.AddLists(blogTags); }
/// <summary> /// 删除Blog以及Blog对应的BlogTags ** 注意:该删除是真实的删除,不可恢复 ** /// </summary> /// <param name="blog"></param> /// <returns></returns> public void DeleteBlog(Blog blog, BlogTagsApplication blogTagsApplication) { Context.Delete(blog); blogTagsApplication.DeleteByBlogId(blog.BlogId); }
/// <summary> /// 修改Blog,会自动修正Blog的数据 /// </summary> /// <param name="newBlog">修改完成的Blog</param> /// /// <param name="blog">要修改的Blog</param> /// <param name="tags"></param> /// <returns></returns> public void EditBlog(Blog newBlog, Blog blog, IList <Tag> tags, TagApplication tagApplication, BlogTagsApplication blogTagsApplication) { //先调用ValidateAndCorrectSubmit验证更合理 newBlog.Date = DateTime.Now; //进行事务添加 blogTagsApplication.DeleteByBlogId(blog.BlogId); //if (!blogTagsApplication.Commit()) //{ // throw new Exception("删除原Blog和标签关系异常"); //} IList <BlogTags> blogTags = blogTagsApplication.UpdateBlogTags(blog, tags, tagApplication); //对齐Blog对象 blog.BTitle = newBlog.BTitle; blog.BContext = newBlog.BContext; blog.BSummary = newBlog.BSummary; blog.BSummaryTrim = newBlog.BSummaryTrim; blog.BHTML = newBlog.BHTML; blog.BScript = newBlog.BScript; blog.BReprint = newBlog.BReprint; //blog.BPV = newBlog.BPV; //blog.Likes = newBlog.Likes; blog.BName = newBlog.BName; blog.BLastCommentUser = newBlog.BLastCommentUser; blog.BLastComment = newBlog.BLastComment; blog.BIsTop = newBlog.BIsTop; blog.BImgTrim = newBlog.BImgTrim; blog.BImg = newBlog.BImg; //blog.BComment = newBlog.BComment; //blog.BClick = newBlog.BClick; blog.ClassifyId = newBlog.ClassifyId; blog.BName = newBlog.BName; Update(blog); blogTagsApplication.AddLists(blogTags); }