public async Task <IActionResult> Create([Bind("ID,Content,PublicationDate,OwnerID,BlogPostId")] Comment comment) { if (ModelState.IsValid) { _context.Add(comment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(comment)); }
public async Task <IActionResult> AddComment([Bind("ID,Content,PublicationDate,BlogPostID")] Comment comment) { if (ModelState.IsValid) { comment.PublicationDate = DateTime.Now; comment.BlogPostId = 1; _context.Add(comment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { return(Content(string.Join(" | ", ModelState.Values .SelectMany(v => v.Errors) .Select(e => e.ErrorMessage)))); } return(View(comment)); }