Exemplo n.º 1
0
        public async Task <ArticlePageListModel> GetArticlesAsync(ArticleFilterModel criterias)
        {
            if (criterias == null)
            {
                criterias = new ArticleFilterModel();
            }

            var filterRequest = new ArticleFilter
            {
                Page     = criterias.Page,
                PageSize = _pagerOptions.PageSize,
                Keyword  = criterias.Search
            };

            try
            {
                var articlePageList = await _articleService.GetAsync(filterRequest);

                var articles = await MapArticlesResultToModelAsync(articlePageList.Collections);

                var articlePage = new ArticlePageListModel(articles)
                {
                    Filter      = criterias,
                    TotalPage   = articlePageList.TotalPage,
                    TotalResult = articlePageList.TotalResult
                };

                return(articlePage);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task <ArticlePageListModel> GetUserArticlesAsync(ClaimsPrincipal claimsPrincipal, ArticleFilterModel criterias)
        {
            if (criterias == null)
            {
                criterias = new ArticleFilterModel();
            }

            if (string.IsNullOrEmpty(criterias.UserIdentityId))
            {
                return(new ArticlePageListModel(new List <ArticleModel>())
                {
                    Filter = criterias
                });
            }

            var currentUserId = GetCurrentUserId(claimsPrincipal);
            var userId        = await _userManager.DecryptUserIdAsync(criterias.UserIdentityId);

            var filterRequest = new ArticleFilter
            {
                Page            = criterias.Page,
                PageSize        = _pagerOptions.PageSize,
                Keyword         = criterias.Search,
                CreatedById     = userId,
                CanGetInactived = currentUserId == userId
            };

            try
            {
                var articlePageList = await _articleService.GetAsync(filterRequest);

                var articles = await MapArticlesResultToModelAsync(articlePageList.Collections);

                var articlePage = new ArticlePageListModel(articles)
                {
                    Filter      = criterias,
                    TotalPage   = articlePageList.TotalPage,
                    TotalResult = articlePageList.TotalResult
                };

                return(articlePage);
            }
            catch (Exception)
            {
                throw;
            }
        }