Ejemplo n.º 1
0
        public async Task <List <ArticleDto> > GetAllArticlesByuserId(Guid userId, int pageIndex, int pagesize)
        {
            using (var articleSvc = new ArticleService())
            {
                var list = await articleSvc.GetAllByPageOrderAsync(pagesize, pageIndex, false).Include(m => m.User).Where(m => m.UseId == userId)
                           .Select(m => new Dto.ArticleDto()
                {
                    Title      = m.Title,
                    BadCount   = m.BadCount,
                    GoodCount  = m.GoodCount,
                    Content    = m.Content,
                    Email      = m.User.Email,
                    CreateTime = m.CreateTime,
                    Id         = m.Id,
                    ImagePath  = m.User.ImagePath,
                }).ToListAsync();

                using (IArticleToCategoryService articleToCategoryService = new ArticleToCategory())
                {
                    foreach (var elem in list)
                    {
                        var cates = await articleToCategoryService.GetAllAsync().Include(m => m.BlogCategory).Where(m => m.ArticleId == elem.Id).ToListAsync();

                        elem.CategoryIds   = cates.Select(m => m.BlogCategoryId).ToArray();
                        elem.CategoryNames = cates.Select(m => m.BlogCategory.CategoryName).ToArray();
                    }
                    return(list);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <ArticleDto> GetOneArticleById(Guid articleId)
        {
            using (BlogSystem.IdAL.IArticleService articleService = new ArticleService())
            {
                var data = await articleService.GetAllAsync()
                           .Include(m => m.User)
                           .Where(m => m.Id == articleId)
                           .Select(m => new Dto.ArticleDto()
                {
                    Id         = m.Id,
                    BadCount   = m.BadCount,
                    Title      = m.Title,
                    Content    = m.Content,
                    CreateTime = m.CreateTime,
                    Email      = m.User.Email,
                    GoodCount  = m.GoodCount,
                    ImagePath  = m.User.ImagePath,
                }).FirstAsync();

                using (IArticleToCategoryService articleToCategoryService = new ArticleToCategory())
                {
                    var cates = await articleToCategoryService.GetAllAsync().Include(m => m.BlogCategory).Where(m => m.ArticleId == data.Id).ToListAsync();

                    data.CategoryIds   = cates.Select(m => m.BlogCategoryId).ToArray();
                    data.CategoryNames = cates.Select(m => m.BlogCategory.CategoryName).ToArray();
                    return(data);
                }
            }
        }
Ejemplo n.º 3
0
        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();
                }
            }
        }