Beispiel #1
0
        public ActionResult Index(int id, int pageNumber = 1, string searchString = null)
        {
            var take          = 3;
            var articleListVm = new List <ArticleListViewModel>();
            var category      = _repo.GetArticleCategory(id);
            var articles      = _repo.GetArticlesByCategoryId(id);

            if (!string.IsNullOrEmpty(searchString))
            {
                articles = articles.Where(a => a.Title.ToLower().Trim().Contains(searchString.ToLower().Trim()) || a.ShortDescription.ToLower().Trim().Contains(searchString.ToLower().Trim()))
                           .ToList();
            }

            int pageCount = articles.Count / take + 1;

            ViewBag.PageCount    = pageCount;
            ViewBag.CategoryId   = category.Id;
            ViewBag.CategoryName = category.Title;
            ViewBag.CurrentPage  = pageNumber;

            var skip = (pageNumber - 1) * take;

            articles = articles.Skip(skip).Take(take).ToList();
            foreach (var item in articles)
            {
                var vm           = new ArticleListViewModel(item);
                var commentCount = _repo.GetArticleComments(item.Id).Count;
                vm.CommentCount = commentCount;
                articleListVm.Add(vm);
            }
            #region BreadCrumb
            var breadCrumbVm = new List <BreadCrumbViewModel>();
            breadCrumbVm.Add(new BreadCrumbViewModel()
            {
                Title = "بلاگ", Href = "/Blog"
            });
            breadCrumbVm.Add(new BreadCrumbViewModel()
            {
                Title = category.Title, Href = $"/Blog/{category.Id}/{category.Title.Replace(" ", "-")}"
            });
            if (!string.IsNullOrEmpty(searchString))
            {
                breadCrumbVm.Add(new BreadCrumbViewModel()
                {
                    Title = $"جستجو : {searchString}", Href = "#"
                });
            }
            ViewBag.BreadCrumb = breadCrumbVm;
            #endregion
            return(View(articleListVm));
        }