Ejemplo n.º 1
0
 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;
     }
 }
Ejemplo n.º 2
0
        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 }));
        }
Ejemplo n.º 3
0
 public async Task <long> SaveComment(CommentsModel obj)
 {
     return(await _commentService.AddAsync(obj));
 }
Ejemplo n.º 4
0
 public async Task <int?> Add(int photoId, string text)
 {
     return(await _commentsService.AddAsync(photoId, text));
 }