Ejemplo n.º 1
0
        public ViewResult Index(int page = 1)
        {
            page = page < 1 ? 1 : page;
            AlexAndNikkiDBEntities dbContext = new AlexAndNikkiDBEntities();

            var blogPostsToShow = dbContext.BlogPosts;

            var pagingInfo = new PagingInfo
            {
                CurrentPage = page,
                ItemsPerPage = 5,
                TotalItems = blogPostsToShow.Count()
            };

            var viewModel = new BlogIndexViewModel
            {
                BlogPosts = blogPostsToShow
                .OrderByDescending(x => x.Date)
                .Skip((page - 1) * 5)
                .Take(5)
                .ToList(),
                PagingInfo = pagingInfo
            };

            return View("Blog", viewModel);
        }
Ejemplo n.º 2
0
        public ViewResult Post(string Id)
        {
            AlexAndNikkiDBEntities db = new AlexAndNikkiDBEntities();
            BlogPost post = db.BlogPosts.Where(x => x.FriendlyUrl == Id).FirstOrDefault();

            return View(post);
        }
Ejemplo n.º 3
0
 public RedirectToRouteResult AddComment(int BlogId, string Name, string Website, string Comment)
 {
     AlexAndNikkiDBEntities db = new AlexAndNikkiDBEntities();
     BlogPost post = db.BlogPosts.Where(x => x.Id == BlogId).First();
     post.BlogPostComments.Add(new BlogPostComment
     {
         BlogPostId = BlogId,
         Name = Name,
         Website = Website,
         Comment = Comment,
         Date = DateTime.Now
     });
     db.SaveChanges();
     return RedirectToAction("Post", new { Id = post.FriendlyUrl });
 }