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; } }
public ActionResult Find(FindArticlesViewModel model) { if (model == null) { model = new FindArticlesViewModel(); } var filterModel = new ArticleFilterModel(); filterModel.MaxDate = model.MaxDate.HasValue ? model.MaxDate.Value : model.MinDate.HasValue ? model.MinDate.Value : DateTime.Now; filterModel.MinDate = model.MinDate.HasValue ? model.MinDate.Value : model.MaxDate.HasValue ? model.MaxDate.Value : DateTime.Now; if (model.Category.HasValue) { filterModel.Categories = filterModel.Categories.Append(model.Category.Value); } var articles = _articleService.Find(filterModel, (model.Page - 1) * _pageSize, _pageSize); model.Articles = Mapper.Map <IEnumerable <Article>, IEnumerable <ArticleViewModel> >(articles); return(View(model)); }
public async Task <IList <ArticleModel> > GetRelevantArticlesAsync(ArticleFilterModel criterias) { if (criterias == null) { criterias = new ArticleFilterModel(); } if (!criterias.Id.HasValue || criterias.Id <= 0) { return(new List <ArticleModel>()); } var filterRequest = new ArticleFilter() { Page = criterias.Page, PageSize = criterias.PageSize.HasValue && criterias.PageSize < _pagerOptions.PageSize ? criterias.PageSize.Value : _pagerOptions.PageSize, Keyword = criterias.Search }; try { var relevantArticles = await _articleService.GetRelevantsAsync(criterias.Id.GetValueOrDefault(), filterRequest); var products = await MapArticlesResultToModelAsync(relevantArticles); return(products); } catch (Exception) { throw; } }
public async Task <ArticleModel> GetArticleAsync(ClaimsPrincipal claimsPrincipal, ArticleFilterModel criterias) { if (criterias == null) { criterias = new ArticleFilterModel(); } if (!criterias.Id.HasValue || criterias.Id <= 0) { return(new ArticleModel()); } var articleResult = await _articleService.FindDetailAsync(new IdRequestFilter <long> { Id = criterias.Id.GetValueOrDefault(), CanGetInactived = true }); var currentUserId = GetCurrentUserId(claimsPrincipal); if (currentUserId != articleResult.CreatedById) { throw new UnauthorizedAccessException(); } var article = await MapArticleResultToModelAsync(articleResult); return(article); }
public Page <ArticleDto> GetallArticle([FromQuery] ArticleFilterModel filter, int pageIndex = 1, int pageSize = 1) { var articles = _repository.Article.GetArticleFilter(filter); var page = new Pager <Article>(articles, pageIndex, pageSize); var getPage = page.GetPage(); var articlesResult = _mapper.Map <IEnumerable <ArticleDto> >(getPage.Items); return(new Page <ArticleDto>(articlesResult, getPage.ItemsCount, getPage.PagesCount, getPage.CurrentIndex)); }
public IEnumerable <Article> Find(ArticleFilterModel filterModel, int skip, int count) { if (filterModel == null) { throw new ArgumentNullException(nameof(filterModel)); } var articles = _articleRepository.GetMany(filterModel.GetExpression()) .OrderByDescending(x => x.PublicationDate).Skip(skip).Take(count); return(articles); }
public IQueryable <Article> GetArticleFilter(ArticleFilterModel filter) { var query = from articles in RepositoryContext.Articles .Where(r => r.DateDeleted == null) .OrderByDescending(r => r.DateCreated) select articles; if (filter.CategoryId != 0) { query = query.Where(r => r.Category == filter.CategoryId); } return(query); }
public async Task <IActionResult> Index(ArticleFilterModel filter) { var articlePageList = await _articleService.GetAsync(new ArticleFilter { CreatedById = filter.CreatedById, CreatedDateFrom = filter.CreatedDateFrom, CreatedDateTo = filter.CreatedDateTo, Page = filter.Page, PageSize = _pagerOptions.PageSize, Keyword = filter.Search, UpdatedById = filter.UpdatedById, CategoryId = filter.CategoryId, StatusId = filter.StatusId, CanGetDeleted = true, CanGetInactived = true }); var articles = articlePageList.Collections.Select(x => new ArticleModel { Id = x.Id, CreatedDate = x.CreatedDate, UpdatedDate = x.UpdatedDate, CreatedById = x.CreatedById, ArticleCategoryId = x.ArticleCategoryId, ArticleCategoryName = x.ArticleCategoryName, Content = x.Content, Description = x.Description, Name = x.Name, PictureId = x.Picture.Id, StatusId = (ArticleStatus)x.StatusId, CreatedBy = x.CreatedBy, UpdatedBy = x.UpdatedBy }); var articlePage = new PageListModel <ArticleModel>(articles) { Filter = filter, TotalPage = articlePageList.TotalPage, TotalResult = articlePageList.TotalResult }; if (_httpHelper.IsAjaxRequest(Request)) { return(PartialView("Partial/_ArticleTable", articlePage)); } return(View(articlePage)); }
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; } }
public async Task <bool> DeleteArticleAsync(ClaimsPrincipal claimsPrincipal, ArticleFilterModel criterias) { try { if (!criterias.Id.HasValue || criterias.Id <= 0) { throw new ArgumentNullException(nameof(criterias.Id)); } var exist = await _articleService.FindAsync(new IdRequestFilter <long> { Id = criterias.Id.GetValueOrDefault(), CanGetInactived = true }); if (exist == null) { return(false); } var currentUserId = GetCurrentUserId(claimsPrincipal); if (currentUserId != exist.CreatedById) { throw new UnauthorizedAccessException(); } return(await _articleService.SoftDeleteAsync(new ArticleModifyRequest { Id = criterias.Id.GetValueOrDefault(), UpdatedById = currentUserId, })); } catch (Exception) { throw; } }
public async Task <IList <ArticleModel> > GetRelevantArticlesAsync([Service] IArticleResolver articleResolver, ArticleFilterModel criterias) { return(await articleResolver.GetRelevantArticlesAsync(criterias)); }
public async Task <ArticleModel> GetArticleAsync(ClaimsPrincipal claimsPrincipal, [Service] IArticleResolver articleResolver, ArticleFilterModel criterias) { return(await articleResolver.GetArticleAsync(claimsPrincipal, criterias)); }
public async Task <ArticlePageListModel> GetArticlesAsync([Service] IArticleResolver articleResolver, ArticleFilterModel criterias) { return(await articleResolver.GetArticlesAsync(criterias)); }