예제 #1
0
        public ActionResult MarkAsOffended(string storyId, string commentId)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(storyId), "Identyfikator artyku³u nie mo¿e byæ pusty."),
                new Validation(() => storyId.ToGuid().IsEmpty(), "Niepoprawny identyfikator artyku³u."),
                new Validation(() => string.IsNullOrEmpty(commentId), "Identyfikator komentarza nie mo¿e byæ pusty."),
                new Validation(() => commentId.ToGuid().IsEmpty(), "Niepoprawny identyfikator komentarza."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteœ zalogowany."),
                new Validation(() => !CurrentUser.CanModerate(), "Nie masz praw do wo³ania tej metody.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Get())
                    {
                        IStory story = _storyRepository.FindById(storyId.ToGuid());

                        if (story == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Podany artyku³ nie istnieje."
                            };
                        }
                        else
                        {
                            IComment comment = story.FindComment(commentId.ToGuid());

                            if (comment == null)
                            {
                                viewData = new JsonViewData {
                                    errorMessage = "Podany komentarz nie istnieje."
                                };
                            }
                            else
                            {
                                _storyService.MarkAsOffended(comment, string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })), CurrentUser);

                                unitOfWork.Commit();

                                viewData = new JsonViewData {
                                    isSuccessful = true
                                };
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("zaznaczania komentarza jako obraŸliwy")
                    };
                }
            }

            return(Json(viewData));
        }
예제 #2
0
        public ActionResult MarkAsOffended(string storyId, string commentId)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(storyId), "Story identifier cannot be blank."),
                new Validation(() => storyId.ToGuid().IsEmpty(), "Invalid story identifier."),
                new Validation(() => string.IsNullOrEmpty(commentId), "Comment identifier cannot be blank."),
                new Validation(() => commentId.ToGuid().IsEmpty(), "Invalid comment identifier."),
                new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated."),
                new Validation(() => !CurrentUser.CanModerate(), "You do not have the privilege to call this method.")
                );

            if (viewData == null)
            {
                try
                {
                    IStory story = _storyRepository.FindById(storyId.ToGuid());

                    if (story == null)
                    {
                        viewData = new JsonViewData {
                            errorMessage = "Specified story does not exist."
                        };
                    }
                    else
                    {
                        IComment comment = story.FindComment(commentId.ToGuid());

                        if (comment == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Specified comment does not exist."
                            };
                        }
                        else
                        {
                            _storyService.MarkAsOffended(comment, string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })), CurrentUser);

                            viewData = new JsonViewData {
                                isSuccessful = true
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("marking comment as offended")
                    };
                }
            }

            return(Json(viewData));
        }
예제 #3
0
        public void Process(string source, bool isSpam, string detailUrl, IComment comment)
        {
            Check.Argument.IsNotEmpty(source, "source");
            Check.Argument.IsNotEmpty(detailUrl, "detailUrl");
            Check.Argument.IsNotNull(comment, "story");

            IStory story = _storyRepository.FindById(comment.ForStory.Id);

            comment = story.FindComment(comment.Id);

            if (isSpam)
            {
                Log.Warning("Possible spam comment submitted : {0}, {1}, {2}".FormatWith(detailUrl, comment.ForStory.Title, comment.ByUser.UserName));
                _eventAggregator.GetEvent <PossibleSpamCommentEvent>().Publish(new PossibleSpamCommentEventArgs(comment, source, detailUrl));
            }
            else
            {
                _eventAggregator.GetEvent <CommentSubmitEvent>().Publish(new CommentSubmitEventArgs(comment, detailUrl));
            }
        }