public async Task EditArticle(Guid articleId, string title, string content, Guid[] categoryIds) { using (BlogSystem.IdAL.IArticleService articleService = new ArticleService()) { var article = await articleService.GetOneByIdAsync(articleId); article.Title = title; article.Content = content; await articleService.EditAsync(article); using (BlogSystem.IdAL.IArticleToCategoryService articleToCategoryService = new ArticleToCategory()) { //删除原有的类别 foreach (var categoryId in articleToCategoryService.GetAllAsync().Where(m => m.ArticleId == articleId)) { await articleToCategoryService.RemoveAsync(categoryId, saved : false); } //foreach (var categoryId in categoryIds) //{ // await articleToCategoryService.CreateAsync(new ArtcleToCategory() { ArticleId = articleId, BlogCategoryId = categoryId }, saved: false); //} await articleToCategoryService.Save(); } } }
public async Task RemoveArticle(Guid articleId) { using (BlogSystem.IdAL.IArticleService articleService = new ArticleService()) { var articles = await articleService.GetOneByIdAsync(articleId); await articleService.RemoveAsync(articles); } }
public async Task GoodCountAdd(Guid articleId) { using (BlogSystem.IdAL.IArticleService articleService = new ArticleService()) { var article = await articleService.GetOneByIdAsync(articleId); article.GoodCount++; await articleService.EditAsync(article); } }
public async Task OppositionArticle(Guid articleId) //反对文章 { using (IArticleService articleService = new ArticleService()) { var article = await articleService.GetOneByIdAsync(articleId); article.BadCount++; await articleService.EditAsync(article); //修改 } }
public async Task RecommendArticle(Guid articleId) //点赞相当于修改 { using (IArticleService articleService = new ArticleService()) { var article = await articleService.GetOneByIdAsync(articleId); article.GoodCounnt++; await articleService.EditAsync(article); //修改 } }
public async Task BedCountAdd(Guid articleId) { using (IArticleService articleService = new ArticleService()) { var article = await articleService.GetOneByIdAsync(articleId); article.BadCount++; await articleService.EditAsync(article); } }
public async Task RemoveArticle(Guid articleId) { using (IArticleService articleSvc = new ArticleService()) { Article article = await articleSvc.GetOneByIdAsync(articleId); await articleSvc.DeleteAsync(article); } using (IArticleToCategory articleToCategorySvc = new ArticleToCategoryService()) { List <ArticleToCategory> list = await articleToCategorySvc.GetAll().Where(m => m.ArticleId == articleId).ToListAsync(); foreach (var item in list) { await articleToCategorySvc.DeleteAsync(item, false); } await articleToCategorySvc.Save(); } }
public async Task EditArticle(Guid articleId, string title, string content, string introContent, Guid[] categoryIds) { using (IArticleService articleSvc = new ArticleService()) { ////处理内容 //string IntroContent = FilterHTML(content); //获取当前文章的实体,修改标题和内容 var article = await articleSvc.GetOneByIdAsync(articleId); article.Title = title; article.Content = content; article.IntroContent = introContent; article.IsTop = categoryIds != null?categoryIds.Contains(Guid.Parse("00000000-0000-0000-0000-000000000001")) : false; await articleSvc.EditAsync(article); using (IArticleToCategory articleToCategorySvc = new ArticleToCategoryService()) { //循环删除一篇文章的多个分类 foreach (var articleToCategory in articleToCategorySvc.GetAll().Where(m => m.ArticleId == articleId)) { await articleToCategorySvc.DeleteAsync(articleToCategory, false); } //循环创建一篇文章多个分类 if (categoryIds != null)//当分类不为空时才循环添加 { foreach (var categoryId in categoryIds) { await articleToCategorySvc.CreatAsync(new ArticleToCategory() { ArticleId = articleId, BlogCategoryId = categoryId }, false); } } await articleToCategorySvc.Save(); } } }
/// <summary> /// 点赞 /// </summary> /// <param name="articleId">文章id</param> /// <param name="userId">用户id</param> /// <returns></returns> public async Task GoodCountAdd(Guid articleId, Guid userId) { int likeCount; int hateCount; using (ILikeHateService likeHateSvc = new LikeHateService()) { string result = await GetLikeHate(articleId, userId); if (result == "none")//没有创建过 { LikeHate likeHate = new LikeHate() { ArticleId = articleId, UserId = userId, Like = true, Hate = false }; await likeHateSvc.CreatAsync(likeHate); } else if (result == "null")//创建了但都为false { LikeHate likeHate = await likeHateSvc.GetAll().Where(m => m.ArticleId == articleId && m.UserId == userId && !m.Like && !m.Hate).FirstAsync(); likeHate.Like = true; await likeHateSvc.EditAsync(likeHate); } likeCount = await likeHateSvc.GetAll().Where(m => m.ArticleId == articleId && m.Like).CountAsync(); hateCount = await likeHateSvc.GetAll().Where(m => m.ArticleId == articleId && m.Hate).CountAsync(); } using (IArticleService articleSvc = new ArticleService()) { var article = await articleSvc.GetOneByIdAsync(articleId); article.BadCount = hateCount; article.GoodCount = likeCount; await articleSvc.EditAsync(article); } }
public async Task EditArticle(Guid articleId, string title, string content, Guid[] categoryIds, bool IsClosingComments) //修改文章 { using (IArticleService articleSvc = new ArticleService()) { var article = await articleSvc.GetOneByIdAsync(articleId); article.Title = title; article.Content = content; article.State = true; //保存修改发布状态改为true article.CreateTime = DateTime.Now; //将发布时间设置为当前时间 article.IsClosingComments = IsClosingComments; await articleSvc.EditAsync(article); using (IArticleToCategoryService articleToCategorySvc = new ArticleToCategoryService()) { //根据文章Id先删除原来所有的类别 foreach (var item in articleToCategorySvc.GetAllAsync().Where(m => m.ArticleId == articleId)) { await articleToCategorySvc.RemoveAsync(item, false); } await articleToCategorySvc.Saved(); //循环完后保存 if (categoryIds != null) { foreach (var item in categoryIds) { await articleToCategorySvc.CreateAsync(new ArticleToCategory() { ArticleId = articleId, BlogCategoryId = item }, false); } } await articleToCategorySvc.Saved(); //循环完后保存 } } }