public async Task Post([FromBody] CommentInputModel commentInput) { try { await service.AddAsync(new Comment(Guid.NewGuid(), commentInput.PostId, commentInput.Text)); } catch (CommentValidationException e) { logger.LogError($"CommentValidationException <{e.Message}> {e.InvalidAttribute}"); throw; } }
public virtual async Task <ActionResult> CommentEditor(CommentEditorModel model) { var isAdmin = HttpContext.User.IsInRole("Admin"); var currentUser = await UserManager.FindByIdAsync(User.Identity.GetUserId()); var currentUserId = currentUser?.Id ?? ""; if (CurrentSettings.UseGoogleRecaptchaForComment) { ViewBag.publicKey = CurrentSettings.GoogleRecaptchaSiteKey; if (!ReCaptcha.Validate(CurrentSettings.GoogleRecaptchaSecretKey)) { ViewBag.RecaptchaLastErrors = ReCaptcha.GetLastErrors(HttpContext); return(View(model)); } } if (!ModelState.IsValid) { return(View(model)); } var published = CurrentSettings.AutoPublishComments; if (isAdmin) { published = model.Published; } await _commentsService.AddAsync( await _commentModelFactory.PrepareTblCommentsAsync(model, currentUser?.Id, published), true); if (published || isAdmin) { TempData["SuccessNotification"] = _localizationService.GetResource("YourCommentSubmitted"); } else { TempData["SuccessNotification"] = _localizationService.GetResource("YourCommentSubmittedAndPublishAfterReview"); } return(RedirectToAction("CommentEditor", new { postId = model.PostId })); }
public async Task <long> SaveComment(CommentsModel obj) { return(await _commentService.AddAsync(obj)); }
public async Task <int?> Add(int photoId, string text) { return(await _commentsService.AddAsync(photoId, text)); }