public ActionResult BlogMonth(int id, int year, int month) { var earliestDate = new DateTime(year, month, 1); var latestDate = new DateTime(year, month, DateTime.DaysInMonth(year, month)); var blog = _repository.Find<Blog>().Where(x => x.Id == id).Execute(); var postIds = _repository.Find<BlogPost>() .Select(x => x.Id) .Where(x => x.Blog.Id == id && x.PublishDate >= earliestDate && x.PublishDate <= latestDate) .OrderByDescending(x => x.PublishDate) .ExecuteScalarList<int>(); var model = new BlogModel { Months = GetMonthsWithPostsForBlog(id), BlogPosts = GetPosts(postIds), Blog = blog }; return View("Blog", model); }
public ActionResult Blog(int id, int page = 0) { var blog = _repository.Find<Blog>().Where(x => x.Id == id).Execute(); var postIds = _repository.Find<BlogPost>() .Select(x => x.Id) .Where(x => x.Blog.Id == id) .Page(page, 5) .OrderByDescending(x => x.PublishDate) .ExecuteScalarList<int>(); var model = new BlogModel { Months = GetMonthsWithPostsForBlog(id), BlogPosts = GetPosts(postIds), Blog = blog }; ViewBag.PageIndex = page; return View(model); }
public ActionResult BlogSearch(int id, string searchString) { var blog = _repository.Find<Blog>().Where(x => x.Id == id).Execute(); var postIds = _repository.Find<BlogPost>() .Select(x => x.Id) .Where(x => x.Blog.Id == id && (x.Content.Contains(searchString) || x.Title.Contains(searchString))) .OrderByDescending(x => x.PublishDate) .ExecuteScalarList<int>(); var model = new BlogModel { Months = GetMonthsWithPostsForBlog(id), BlogPosts = GetPosts(postIds), Blog = blog }; return View("Blog", model); }