コード例 #1
0
ファイル: ReviewsWebService.cs プロジェクト: gchokov/feather
        public AuthorReviewedViewModel Get(AuthorReviewedGetRequest request)
        {
            var authorComments = CommentsUtilitiesReflector.GetCommentsByThreadForCurrentAuthorWithRating(request.ThreadKey);

            return(new AuthorReviewedViewModel()
            {
                AuthorAlreadyReviewed = authorComments.Any()
            });
        }
コード例 #2
0
ファイル: ReviewsWebService.cs プロジェクト: gchokov/feather
        private CommentResponse SubmitCommentInternal(CommentCreateRequest commentData, IThread thread, IAuthor author)
        {
            var cs            = SystemManager.GetCommentsService();
            var currentConfig = CommentsUtilitiesReflector.GetThreadConfigByType(thread.Type, thread.Key);

            if (currentConfig.RequiresAuthentication)
            {
                if (author.Key.IsNullOrWhitespace() || author.Key == Guid.Empty.ToString())
                {
                    throw new InvalidOperationException("Comment cannot be submitted at the moment. Please refresh the page and try again.");
                }
            }

            if (currentConfig.EnableRatings)
            {
                if (commentData.Rating == null)
                {
                    throw new InvalidOperationException("A message displayed when ratings are allowed and a comment is submitted without rating.");
                }

                if (CommentsUtilitiesReflector.GetCommentsByThreadForCurrentAuthorWithRating(thread.Key).Any())
                {
                    throw new InvalidOperationException("Only one comment with rating is allowed per user.");
                }
            }

            var authorIp     = CommentsUtilitiesReflector.GetIpAddressFromCurrentRequest();
            var commentProxy = new CommentProxy(commentData.Message, thread.Key, author, authorIp, commentData.Rating);

            commentProxy.CustomData = commentData.CustomData;

            if (currentConfig.RequiresApproval)
            {
                commentProxy.Status = StatusConstants.WaitingForApproval;
            }
            else
            {
                commentProxy.Status = StatusConstants.Published;
            }

            IComment newComment = cs.CreateComment(commentProxy);

            var result = CommentsUtilitiesReflector.GetCommentResponse(newComment, ClaimsManager.GetCurrentIdentity().IsBackendUser);

            if (commentData.Captcha != null)
            {
                CommentsUtilitiesReflector.RemoveCaptchaFromTempStorage(commentData.Captcha.Key);
            }

            ServiceUtility.DisableCache();

            return(result);
        }