public List <ArticleViewModel> Search(ArticleSearchModel searchModel)
        {
            var query = _context.Articles.Select(x => new ArticleViewModel
            {
                Id               = x.Id,
                CategoryId       = x.CategoryId,
                Category         = x.Category.Name,
                Picture          = x.Picture,
                PublishDate      = x.PublishDate.ToFarsi(),
                ShortDescription = x.ShortDescription.Substring(0, Math.Min(x.ShortDescription.Length, 50)) + " ...",
                Title            = x.Title
            });

            if (!string.IsNullOrWhiteSpace(searchModel.Title))
            {
                query = query.Where(x => x.Title.Contains(searchModel.Title));
            }

            if (searchModel.CategoryId > 0)
            {
                query = query.Where(x => x.CategoryId == searchModel.CategoryId);
            }

            return(query.OrderByDescending(x => x.Id).ToList());
        }
Exemplo n.º 2
0
        public ActionResult Search(ArticleSearchModel model)
        {
            // To Bind the category drop down in search section
            ViewBag.Categories = this.Data.Categories.All();

            // Get Products
            model.Articles = _articles.All()
                             .Where(
                x =>
                (model.ProductName == null || x.Name.Contains(model.ProductName)) &&
                (model.Price == null || x.Price < model.Price) &&
                (model.Category == null || x.CategoryId == model.Category)
                )
                             //.OrderBy(model.Sort + " " + model.SortDir)
                             //.Skip((model.Page - 1) * model.PageSize)
                             //.Take(model.PageSize)
                             .ToList();

            // total records for paging
            model.TotalRecords = _articles.All()
                                 .Count(x =>
                                        (model.ProductName == null || x.Name.Contains(model.ProductName)) &&
                                        (model.Price == null || x.Price < model.Price) &&
                                        (model.Category == null || x.CategoryId == model.Category)
                                        );


            return(View(model));
        }
Exemplo n.º 3
0
        public IPagedList <Article> GetArticles(ArticleList page, ArticleSearchModel model)
        {
            var query = _session.QueryOver <Article>()
                        .Where(a => a.Parent == page);

            if (!String.IsNullOrEmpty(model.Category))
            {
                Tag tagAlias = null;
                query = query.JoinAlias(article => article.Tags, () => tagAlias).Where(() => tagAlias.Name.IsInsensitiveLike(model.Category, MatchMode.Exact));
            }

            if (model.Month.HasValue)
            {
                query =
                    query.Where(
                        article => article.PublishOn != null && article.PublishOn.Value.Month == model.Month);
            }
            if (model.Year.HasValue)
            {
                query =
                    query.Where(
                        article => article.PublishOn != null && article.PublishOn.Value.Year == model.Year);
            }

            return(query.OrderBy(x => x.PublishOn).Desc.Paged(model.Page, page.PageSize));
        }
Exemplo n.º 4
0
        public void OnGet(ArticleSearchModel searchModel)
        {
            ArticleCategories = new SelectList(_articleCategoryApplication.GetArticleCategories(),
                                               "Id", "Name");

            Articles = _articleApplication.Search(searchModel);
        }
Exemplo n.º 5
0
        public ActionResult InitDataTable(ArticleSearchModel model)
        {
            var query = _articleService.GetAllArticle(title: model.SearchTitle, categoryId: model.SearchCategoryId, showHidden: true,
                                                      pageIndex: model.iDisplayStart / model.iDisplayLength, pageSize: model.iDisplayLength);

            var filterResult = query.Select(t => new ArticleListModel
            {
                Id           = t.Id,
                Title        = t.Title,
                Views        = t.Views,
                CommentCount = t.CommentCount,
                Published    = t.Published,
                CreateDate   = WebHelper.ConvertToUserTime(t.CreateDate)
            });

            int sortId = model.iDisplayStart + 1;
            var result = from t in filterResult
                         select new[]
            {
                sortId++.ToString(),
                t.Title,
                t.CreateDate,
                t.Views.ToString(),
                t.CommentCount.ToString(),
                t.Published.ToString(),
                t.Id.ToString(),
                t.Id.ToString(),
            };

            return(DataTableJsonResult(model.sEcho, model.iDisplayStart, query.TotalCount, query.TotalCount, result));
        }
Exemplo n.º 6
0
        public ActionResult List()
        {
            var model = new ArticleSearchModel();

            model.SearchCategories.AddRange(
                _categoryService.GetAllCategory().Select(t => new SelectListItem
            {
                Text  = t.Name,
                Value = t.Id.ToString(),
            })
                );
            return(View(model));
        }
Exemplo n.º 7
0
        // GET: backend/Article
        public ActionResult Index(ArticleSearchModel model, int page = 1)
        {
            ArticleFilter filter = new ArticleFilter();

            filter.Title  = model.Title;
            filter.Status = Consts.ArticleStatus_All;
            var pager = PageReq <ArticleFilter> .Create(filter, page);

            pager.OrderBy = "order by addtime";

            var data = jlService.ArticlePage(pager);

            ViewBag.articleQuery = filter;
            ViewBag.ReturnUrl    = Request.Url.PathAndQuery;
            return(View(data));
        }
 public List <ArticleViewModel> Search(ArticleSearchModel searchModel)
 {
     return(_articleRepository.Search(searchModel));
 }
Exemplo n.º 9
0
 public ActionResult Show(ArticleList page, [IoCModelBinder(typeof(ArticleListModelBinder))] ArticleSearchModel model)
 {
     ViewData["paged-articles"]       = _articleService.GetArticles(page, model);
     ViewData["article-search-model"] = model;
     return(View(page));
 }