Пример #1
0
 public IActionResult Detail(int Id)
 {
     using (var ctx = new ApplicationContext())
     {
         Post           post     = ctx.Posts.Find(Id);
         List <Comment> comments = ctx.Comments.Where(x => x.PostId == Id && x.Active == true).ToList();
         PostDetailVm   model    = new PostDetailVm()
         {
             Id       = post.Id,
             Title    = post.Title,
             Image    = post.Image,
             Like     = post.Like,
             DisLike  = post.DisLike,
             Content  = post.Content,
             Comments = comments
         };
         return(View(model));
     }
 }
Пример #2
0
 public IActionResult Comment(PostDetailVm model)
 {
     if (ModelState.IsValid)
     {
         using (var ctx = new ApplicationContext())
         {
             var comment = new Comment()
             {
                 PostId = model.Id,
                 Name   = model.CommentVm.Name,
                 Email  = model.CommentVm.Email,
                 Text   = model.CommentVm.Text,
                 Active = false
             };
             ctx.Comments.Add(comment);
             ctx.SaveChanges();
         }
     }
     return(RedirectToAction("Detail", new { Id = model.Id }));
 }