Exemplo n.º 1
0
        // GET: Blogs
        public ActionResult Index(int?category, int page = 1)
        {
            VwBlog model = new VwBlog();

            model.BlogCategories = db.BlogCategories.ToList();
            model.Category       = category;
            model.Tags           = db.Tags.ToList();
            model.LatestBlogs    = db.Blogs.OrderByDescending(d => d.Date).Take(4).ToList();
            model.Blogs          = db.Blogs.Include("Author").OrderByDescending(d => d.Date).Skip((page - 1) * 4).Take(4).ToList();
            model.TotalPage      = Convert.ToInt32(Math.Ceiling(db.Blogs.Count() / 4.0));

            if (page < 1 || page > model.TotalPage)
            {
                return(HttpNotFound());
            }

            model.Page = page;
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Index(int?category, int page = 1)
        {
            VwBlog model = new VwBlog();

            model.Blogs = _context.Blogs.Include("Category").Include("Doctor").Where(c => (category != null ? c.CategoryId == category : true)).OrderByDescending(b => b.Date).Skip((page - 1) * 4).Take(4).ToList();

            model.TotalPage = Convert.ToInt32(Math.Ceiling(_context.Blogs.Count() / 4.00));

            model.Categories = _context.Categories.ToList();

            model.Setting = _context.Settings.FirstOrDefault();

            model.LastPosts = _context.Blogs.Include("Category").Include("Doctor").OrderByDescending(b => b.Date).Take(6).ToList();


            if (page < 1 || page > model.TotalPage)
            {
                return(HttpNotFound());
            }

            model.Page = page;

            return(View(model));
        }