示例#1
0
        public ActionResult Approve(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator artyku³u nie mo¿e byæ pusty."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikator artyku³u."),
                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(id.ToGuid());

                        if (story == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Podany artyku³ nie istnieje."
                            };
                        }
                        else
                        {
                            if (story.IsApproved())
                            {
                                viewData = new JsonViewData {
                                    errorMessage = "Podany artyku³ ju¿ zosta³ zatwierdzony jako spam."
                                };
                            }
                            else
                            {
                                _storyService.Approve(story, 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("aprobowania artyku³u")
                    };
                }
            }

            return(Json(viewData));
        }
示例#2
0
        public virtual void Approve(IStory theStory, string storyUrl, IUser byUser)
        {
            Check.Argument.IsNotNull(theStory, "theStory");
            Check.Argument.IsNotEmpty(storyUrl, "storyUrl");
            Check.Argument.IsNotNull(byUser, "byUser");

            if (!theStory.IsApproved())
            {
                theStory.Approve(SystemTime.Now());
                _emailSender.NotifyStoryApprove(storyUrl, theStory, byUser);
            }
        }
示例#3
0
        public ActionResult Approve(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Story identifier cannot be blank."),
                new Validation(() => id.ToGuid().IsEmpty(), "Invalid story 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(id.ToGuid());

                    if (story == null)
                    {
                        viewData = new JsonViewData {
                            errorMessage = "Specified story does not exist."
                        };
                    }
                    else
                    {
                        if (story.IsApproved())
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Specified story has been already approved."
                            };
                        }
                        else
                        {
                            _storyService.Approve(story, 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("approving story")
                    };
                }
            }

            return(Json(viewData));
        }
示例#4
0
        public virtual void Approve(IStory theStory, string storyUrl, IUser byUser)
        {
            Check.Argument.IsNotNull(theStory, "theStory");
            Check.Argument.IsNotEmpty(storyUrl, "storyUrl");
            Check.Argument.IsNotNull(byUser, "byUser");

            if (!theStory.IsApproved())
            {
                using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                {
                    theStory.Approve(SystemTime.Now());

                    _eventAggregator.GetEvent <StoryApproveEvent>().Publish(new StoryApproveEventArgs(theStory, byUser, storyUrl));

                    unitOfWork.Commit();
                }
            }
        }