Beispiel #1
0
        public List <ArticleDTO> GetAllArticlesByUserId(Guid userId, int pageIndex, int pageSize, out int totalCount)
        {
            // IQueryable<Article> articles = _articleDAL.GetEntities(m => m.ArticleUserId == userId);
            IQueryable <Article> articles    = _articleDAL.GetPageEntitiesOrdered(pageIndex, pageSize, out totalCount, m => m.ArticleUserId == userId, m => m.ArticleCreateDateTime, false);
            List <ArticleDTO>    articleDTOs = new List <ArticleDTO>();

            foreach (Article article in articles)
            {
                var           categories = _articleToCategoryDAL.GetCategoriesByArticleId(article.ArticleId).ToList();
                User          user       = _userDAL.GetUserById(article.ArticleUserId);
                List <string> cateNames  = new List <string>();
                foreach (ArticleToCategory articleToCategory in categories)
                {
                    cateNames.Add(_categoryDAL.GetCategoryById(articleToCategory.ArticleToCategoryCategoryId).CategoryName);
                }

                articleDTOs.Add(new ArticleDTO()
                {
                    Id             = article.ArticleId,
                    Title          = article.ArticleTitle,
                    Content        = article.ArticleContent,
                    CreateDateTime = article.ArticleCreateDateTime,
                    UserEmail      = user.UserEmail,
                    LikeCount      = article.ArticleLikeCount,
                    UnlikeCount    = article.ArticleUnlikeCount,
                    ImagePath      = user.UserImagePath,
                    CategoryIds    = categories.Select(m => m.ArticleToCategoryCategoryId.ToString()).ToArray(),
                    CategoryNames  = cateNames.ToArray()
                });
            }
            return(articleDTOs);
        }