예제 #1
0
        public async Task <CommentViewModel> SaveComment(CommentCreateRequest request, bool isAdmin)
        {
            var blog = _dataProvider.GetBlog();

            var validation = await _reCaptchaValidator.Validate(new ReCaptchaValidationRequest
            {
                Resonse = request.ReCaptchaToken,
                Secret  = blog.CaptchaSecret
            });

            if (!validation.success)
            {
                return(null);
            }

            var gravatarHash = _gravatarService.GetGravatarHash(request.AuthorEmail);

            request.Text = request.Text.Replace("\n", "<br />");
            var comment =
                _dataProvider.CreateComment(request.PostId, request.AuthorName, request.AuthorEmail, request.Text, gravatarHash, isAdmin);

            if (blog.SendCommentEmail)
            {
                await _emailService.SendCommentEmail(request);
            }

            return(_mapper.Map <CommentViewModel>(comment));
        }