public IActionResult ShowPartialWithViewModel() { BlogCommentVM vm = new BlogCommentVM(); vm.Blogs = _context.Blog.ToList(); vm.Comments = _context.Comment.ToList(); return(View(vm)); }
public BlogCommentVM GetBlogData(int blogId) { BlogCommentVM vm; var blog = db.Blogs.Find(blogId); var comments = db.Comments.Where(x => x.BlogId == blogId).ToList(); vm = new BlogCommentVM() { Blogs = blog, Comments = comments }; return(vm); }
public ActionResult Detay(BlogCommentVM vm, int id) { try { vm.Comment.BlogId = id; db.Comments.Add(vm.Comment); db.SaveChanges(); ViewBag.Success = "True"; } catch (Exception) { ViewBag.Success = "False"; } return(View(GetBlogData(id))); }
public async Task <IActionResult> BlogComment(BlogCommentVM blogCommentVM) { BlogComment blogComment = new BlogComment() { Blog = _context.Blogs.Find(blogCommentVM.id), Name = blogCommentVM.name, Email = blogCommentVM.email, Subject = blogCommentVM.subject, Description = blogCommentVM.message }; await _context.BlogComments.AddAsync(blogComment); await _context.SaveChangesAsync(); //return View(); return(Content("Success!!!")); }