public async Task <bool> SaveChangesAsync() { if (await _context.SaveChangesAsync() > 0) { return(true); } return(false); }
public async Task <IActionResult> CreateComment(int PostId, Comment comment, string captcha) { if (!await _captchaValidator.IsCaptchaPassedAsync(captcha)) { ModelState.AddModelError("captcha", "Captcha validation failed"); } if (ModelState.IsValid) { _context.Add(comment); await _context.SaveChangesAsync(); ViewData["Message"] = "Success"; return(View("Post", new Comment { PostId = comment.PostId })); } return(RedirectToAction("Post", new { id = comment.PostId })); }