Exemple #1
0
        public async Task <ArticleDto> GetOneArticleById(Guid articleId)
        {
            using (var articleSvc = new DAL.ArticleService())
            {
                var data = await articleSvc.GetAllAsync().Include(m => m.User).Where(m => m.Id == articleId).Select(m => new Dto.ArticleDto()
                {
                    Id         = m.Id,
                    Title      = m.Title,
                    Content    = m.Content,
                    CreateTime = m.CreateTime,
                    GoodCount  = m.GoodCount,
                    BadCount   = m.BadCount,
                    Email      = m.User.Email,
                    ImagePath  = m.User.ImagePath
                }).FirstAsync();

                using (var articleToCategroySvc = new DAL.ArticleToCategoryService())
                {
                    var articleToCategroyData = articleToCategroySvc.GetAllAsync().Include(m => m.BlogCategory).Where(m => m.ArticleId == data.Id);
                    data.CategoryIds   = articleToCategroyData.Select(m => m.BlogCategoryId).ToArray();
                    data.CategoryNames = articleToCategroyData.Select(m => m.BlogCategory.CategoryName).ToArray();

                    return(data);
                }
            }
        }
Exemple #2
0
        public async Task EditArticle(Guid articleId, string title, string content, Guid[] categoryIds)
        {
            using (var articleSvc = new DAL.ArticleService())
            {
                var article = await articleSvc.GetOneByIdAsync(articleId);

                article.Title   = title;
                article.Content = content;
                await articleSvc.EditAsync(article);
            }
            using (var articleToCategorySvc = new DAL.ArticleToCategoryService())
            {
                foreach (var item in articleToCategorySvc.GetAllAsync().Where(m => m.ArticleId == articleId))
                {
                    await articleToCategorySvc.RemoveAsync(item, false);
                }
                foreach (var item in categoryIds)
                {
                    await articleToCategorySvc.CreateAsync(new Models.ArticleToCategory()
                    {
                        ArticleId = articleId, BlogCategoryId = item
                    }, false);
                }
                await articleToCategorySvc.Save();
            }
        }
Exemple #3
0
        public async Task <List <ArticleDto> > GetAllArticlesByUserId(Guid userId, int pageIndex, int pageSize)
        {
            using (var articleSvc = new DAL.ArticleService())
            {
                var list = await articleSvc.GetAllByPageOrderAsync(pageSize, pageIndex, false).Include(m => m.User).Where(m => m.UserId == userId).Select(m => new ArticleDto()
                {
                    Id         = m.Id,
                    Title      = m.Title,
                    Content    = m.Content,
                    CreateTime = m.CreateTime,
                    GoodCount  = m.GoodCount,
                    BadCount   = m.BadCount,
                    Email      = m.User.Email,
                    ImagePath  = m.User.ImagePath
                }).ToListAsync();

                using (var articleToCategroySvc = new DAL.ArticleToCategoryService())
                {
                    foreach (var item in list)
                    {
                        var articleToCategroyData = articleToCategroySvc.GetAllAsync().Include(m => m.BlogCategory).Where(m => m.ArticleId == item.Id);
                        item.CategoryIds   = articleToCategroyData.Select(m => m.BlogCategoryId).ToArray();
                        item.CategoryNames = articleToCategroyData.Select(m => m.BlogCategory.CategoryName).ToArray();
                    }
                    return(list);
                }
            }
        }