Beispiel #1
0
        public ActionResult Details(string slug)
        {
            Post post = new Post();
            using (BlogMvcContext db = new BlogMvcContext())
            {
                post = db.Posts
                    .Include(p => p.Comments)
                    .Include(p => p.Category)
                    .Include(p => p.User)
                    .Where(p => p.Slug == slug)
                    .FirstOrDefault();

            }



            return View(post);
        }
Beispiel #2
0
        public ActionResult Comment(Comment newComment)
        {
            Post post = new Post();
            using (BlogMvcContext db = new BlogMvcContext())
            {
                post = db.Posts
                    .Include(p => p.Comments)
                    .Include(p => p.Category)
                    .Include(p => p.User)
                    .Where(p => p.Id == newComment.Post_Id)
                    .FirstOrDefault();
            }

            if( !this.ModelState.IsValid )
            {
                return View("Details", post);
            }

            using (BlogMvcContext db = new BlogMvcContext())
            {
                newComment.Created = DateTime.Now;
                db.Comments.Add(newComment);
                db.SaveChanges();
            }

            return RedirectToAction("Details", new { slug = post.Slug });

        }