示例#1
0
        public IHttpActionResult Get([FromUri] SearchArticleModel searchArticleModel)
        {
            IEnumerable <Article> arcticles = null;
            int?allCount = 0;

            if (searchArticleModel == null)
            {
                arcticles = _articleService.GetAll();
                allCount  = arcticles?.ToList()?.Count();
            }
            else
            {
                allCount  = _articleService.SearchArcticles(searchArticleModel)?.Count();
                arcticles = _articleService.SearchArcticles(searchArticleModel).Pagination((searchArticleModel.Page - 1) * searchArticleModel.Size, searchArticleModel.Size).ToList();
            }

            if (allCount == null)
            {
                return(NotFound());
            }

            var articlesBindingModel = Mapper.Map <IEnumerable <Article>, IEnumerable <ArticleViewModel> >(arcticles);

            return(Ok(new
            {
                Items = articlesBindingModel,
                TotalCount = allCount
            }));
        }
示例#2
0
        public IQueryable <Domain.Entities.Article> SearchArcticles(SearchArticleModel searchVeteranModel)
        {
            var keyWord   = _articleSpecification.KeyWord(searchVeteranModel);
            var arcticles = _articleRepository.GetSpec(keyWord.Predicate).OrderBy(x => x.CreatedDateTime);

            return(arcticles);
        }
示例#3
0
        public IActionResult Index()
        {
            var search = new SearchArticleModel();

            search.Take = 20;
            var articles = _articleService.GetArticles(search).Data;

            ViewBag.Articles = articles;
            return(View());
        }
示例#4
0
        public IActionResult Channel(string id)
        {
            var search = new SearchArticleModel();

            if (!string.IsNullOrWhiteSpace(id))
            {
                search.ChannelId = id;
                ViewBag.Channel  = _blogService.GetChannel(id);
            }
            search.Take = 20;
            var articles = _articleService.GetArticles(search).Data;

            ViewBag.Articles = articles;
            return(View());
        }
示例#5
0
        public ResultModel <List <ArticleListModel> > GetArticles(SearchArticleModel model)
        {
            model.Sort = new List <Sort> {
                new Sort {
                    Field = "Created", Desc = true
                }
            };
            Expression <Func <Article, bool> > ex = t => true;

            if (!string.IsNullOrWhiteSpace(model.Id))
            {
                ex = t => t.Id.Contains(model.Id);
            }
            if (!string.IsNullOrWhiteSpace(model.Title))
            {
                ex = ex.And(t => t.Title.Contains(model.Title));
            }
            if (!string.IsNullOrWhiteSpace(model.UserName))
            {
                ex = ex.And(t => t.User.UserName.Contains(model.UserName));
            }
            if (!string.IsNullOrWhiteSpace(model.CreatedDate))
            {
                DateTime.TryParse(model.CreatedDate, out var createdDate);
                ex = ex.And(t => t.Created.Date == createdDate);
            }
            if (!string.IsNullOrWhiteSpace(model.ChannelId))
            {
                ex = ex.And(t => t.ChannelId == model.ChannelId);
            }
            var users = _articleRepository.GetAll().Include(i => i.Channel).Include(i => i.User).Include(i => i.Files).Where(ex).ToDataSourceResult(model);

            return(new ResultModel <List <ArticleListModel> >
            {
                Data = _mapper.Map <List <ArticleListModel> >(users.Data),
                Total = users.Total
            });
        }
示例#6
0
 public ActionResult <ResultModel <List <ArticleListModel> > > GetArticles(SearchArticleModel model)
 {
     return(_articleService.GetArticles(model));
 }
 public Specification <Article> KeyWord(SearchArticleModel searchArticleModel)
 {
     return(GetByName(searchArticleModel.Name).And(!IsDeleted()));
 }