Exemplo n.º 1
0
        // GET: Article
        public ActionResult Index(string sortOrder = "Date", int page = 1, string parameters = "")
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                ParseParams(parameters, out string searchString, out string filterString);

                var articles = session.Query <Article>().Where(a => a.PubDate <= DateTime.Now && a.Visibility == true);

                DateFilter filter = new DateFilter(filterString);
                articles = filter.FilterByDate(articles);

                if (searchString != "")
                {
                    articles = articles.Where(a => a.Title.Contains(searchString) ||
                                              a.Description.Contains(searchString));
                }

                articles = Sort(articles, sortOrder);

                var articlesList = articles.ToList();
                int pageSize     = 10;
                IEnumerable <Article> articlesPerPages = articlesList.Skip((page - 1) * pageSize).Take(pageSize);
                PageInfo pageInfo = new PageInfo
                {
                    PageNumber = page,
                    PageSize   = pageSize,
                    TotalItems = articlesList.Count
                };
                ArticleIndexViewModel articlesViewModel = new ArticleIndexViewModel
                {
                    Articles = articlesPerPages,
                    PageInfo = pageInfo
                };
                return(View(articlesViewModel));
            }
        }