예제 #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));
 }
예제 #7
0
 public Specification <Article> KeyWord(SearchArticleModel searchArticleModel)
 {
     return(GetByName(searchArticleModel.Name).And(!IsDeleted()));
 }