public virtual void StoryDemoted(IStory theStory, IUser byUser)
        {
            Check.Argument.IsNotNull(theStory, "theStory");
            Check.Argument.IsNotNull(byUser, "byUser");

            if (CanChangeScoreForStory(theStory, byUser))
            {
                // It might not decrease the same value which was increased when promoting the story
                // depending upon the story status(e.g. published/upcoming), but who cares!!!
                UserAction reason;
                decimal    score;

                if (theStory.IsPublished())
                {
                    score  = _userScoreTable.PublishedStoryPromoted;
                    reason = UserAction.PublishedStoryDemoted;
                }
                else
                {
                    score  = _userScoreTable.UpcomingStoryPromoted;
                    reason = UserAction.UpcomingStoryDemoted;
                }

                byUser.DecreaseScoreBy(score, reason);
            }
        }
示例#2
0
 public static bool HasRightsToEditStory(this IUser user, IStory story)
 {
     if (story == null || user == null)
     {
         return(false);
     }
     return(user.CanModerate() || (user.Id == story.PostedBy.Id &&
                                   SystemTime.Now() < story.CreatedAt.AddMinutes(20) &&
                                   story.IsPublished() == false));
 }
示例#3
0
        public virtual void Spam(IStory theStory, string storyUrl, IUser byUser)
        {
            Check.Argument.IsNotNull(theStory, "theStory");
            Check.Argument.IsNotEmpty(storyUrl, "storyUrl");
            Check.Argument.IsNotNull(byUser, "byUser");

            if (!theStory.IsPublished())
            {
                _userScoreService.StorySpammed(theStory);
                _storyRepository.Remove(theStory);
                _emailSender.NotifyConfirmSpamStory(storyUrl, theStory, byUser);
            }
        }
示例#4
0
        private void AppendStoryInAtom(XContainer feed, IStory story, UrlHelper urlHelper, string dateFormat)
        {
            string detailUrl        = string.Concat(_model.RootUrl, urlHelper.RouteUrl("Detail", new { name = story.UniqueName }));
            string storyDescription = PrepareDescription(story, detailUrl);

            string userUrl = string.Concat(_model.RootUrl, urlHelper.RouteUrl("User", new { name = story.PostedBy.Id.Shrink(), tab = UserDetailTab.Promoted, page = 1 }));

            XElement entry = new XElement(
                atom + "entry",
                new XElement(atom + "id", detailUrl),
                new XElement(atom + "title", story.Title),
                new XElement(atom + "updated", story.CreatedAt.ToString(dateFormat, Constants.CurrentCulture)),
                new XElement(atom + "content", new XAttribute("type", "html"), storyDescription),
                new XElement(atom + "link", new XAttribute("rel", "alternate"), new XAttribute("href", detailUrl)),
                new XElement(atom + "contributor", new XElement(atom + "name", story.PostedBy.UserName), new XElement(atom + "uri", userUrl))
                );

            if (story.IsPublished())
            {
                entry.Add(new XElement(atom + "published", story.PublishedAt.Value.ToString(dateFormat, Constants.CurrentCulture)));
            }

            if (story.HasTags())
            {
                AppendTagsInAtom(entry, story.Tags, urlHelper);
            }

            entry.Add(new XElement(_ns + "link", detailUrl));
            entry.Add(new XElement(_ns + "voteCount", story.VoteCount));
            entry.Add(new XElement(_ns + "viewCount", story.ViewCount));
            entry.Add(new XElement(_ns + "commentCount", 0));
            //GH:71 begin
            entry.Add(new XElement(_ns + "textContent", story.TextDescription));
            entry.Add(new XElement(_ns + "articleLink", story.Url));
            entry.Add(new XElement(_ns + "imageLink", ThumbnailHelper.GetThumbnailVirtualPathForStory(story.Id.Shrink(), ThumbnailSize.Small, true).AttributeEncode()));
            //GH:71 end

            ICategory category    = story.BelongsTo;
            string    categoryUrl = string.Concat(_model.RootUrl, urlHelper.Action("Category", "Story", new { name = category.UniqueName }));

            entry.Add(new XElement(_ns + "category", new XAttribute("term", category.Name), new XAttribute("scheme", categoryUrl)));

            feed.Add(entry);
        }
        private void StoryRemoved(IStory theStory, UserAction action)
        {
            Check.Argument.IsNotNull(theStory, "theStory");

            DateTime expireDate = theStory.CreatedAt.AddHours(_settings.MaximumAgeOfStoryInHoursToPublish);

            foreach (IMarkAsSpam markAsSpam in theStory.MarkAsSpams)
            {
                if (markAsSpam.ByUser.IsPublicUser() && (markAsSpam.MarkedAt <= expireDate))
                {
                    markAsSpam.ByUser.DecreaseScoreBy(_userScoreTable.StoryMarkedAsSpam, action);
                }
            }

            foreach (IComment comment in theStory.Comments)
            {
                if (comment.ByUser.IsPublicUser() && (comment.CreatedAt <= expireDate))
                {
                    comment.ByUser.DecreaseScoreBy(_userScoreTable.StoryCommented, action);
                }
            }

            foreach (IVote vote in theStory.Votes)
            {
                if (!theStory.IsPostedBy(vote.ByUser))
                {
                    if (vote.ByUser.IsPublicUser() && (vote.PromotedAt <= expireDate))
                    {
                        decimal score = theStory.IsPublished() ?
                                        _userScoreTable.PublishedStoryPromoted :
                                        _userScoreTable.UpcomingStoryPromoted;

                        vote.ByUser.DecreaseScoreBy(score, action);
                    }
                }
            }

            if (theStory.PostedBy.IsPublicUser())
            {
                theStory.PostedBy.DecreaseScoreBy(_userScoreTable.StorySubmitted, action);
            }
        }
示例#6
0
        private void AppendStoryInRss(XContainer channel, IStory story, UrlHelper urlHelper, string dateFormat)
        {
            string detailUrl        = string.Concat(_model.RootUrl, urlHelper.RouteUrl("Detail", new { name = story.UniqueName }));
            string storyDescription = PrepareDescription(story, detailUrl);

            XElement item = new XElement(
                "item",
                new XElement("guid", new XAttribute("isPermaLink", "true"), detailUrl),
                new XElement("link", detailUrl),
                new XElement("title", story.Title),
                new XElement("description", new XCData(storyDescription)),
                new XElement("comments", "{0}#comments".FormatWith(detailUrl))
                );

            if (story.IsPublished())
            {
                item.Add(new XElement("pubDate", story.PublishedAt.Value.ToString(dateFormat, Constants.CurrentCulture)));
            }

            if (story.HasTags())
            {
                AppendTagsInRss(item, story.Tags, urlHelper);
            }

            item.Add(new XElement(_ns + "link", detailUrl));
            item.Add(new XElement(_ns + "voteCount", story.VoteCount));
            item.Add(new XElement(_ns + "viewCount", story.ViewCount));
            item.Add(new XElement(_ns + "commentCount", 0));
            item.Add(new XElement(_ns + "id", story.Id.Shrink()));

            ICategory category = story.BelongsTo;

            string categoryUrl = string.Concat(_model.RootUrl, urlHelper.Action("Category", "Story", new { name = category.UniqueName }));

            item.Add(new XElement(_ns + "category", new XAttribute("domain", categoryUrl), category.Name));

            string userUrl = string.Concat(_model.RootUrl, urlHelper.RouteUrl("User", new { name = story.PostedBy.Id.Shrink(), tab = UserDetailTab.Promoted, page = 1 }));

            item.Add(new XElement(_ns + "contributer", new XAttribute("domain", userUrl), story.PostedBy.UserName));

            channel.Add(item);
        }
示例#7
0
        public virtual void Spam(IStory theStory, string storyUrl, IUser byUser)
        {
            Check.Argument.IsNotNull(theStory, "theStory");
            Check.Argument.IsNotEmpty(storyUrl, "storyUrl");
            Check.Argument.IsNotNull(byUser, "byUser");

            if (!theStory.IsPublished())
            {
                using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                {
                    //Removing story is supposed to be before Publishing Spam Event. However, because that Entity Framework
                    //set all related objects to null, a NullReferenceException will occure within event subscribers, as they
                    //might access related objects such as PostedBy, BelongsTo, Votes etc...
                    _eventAggregator.GetEvent <StorySpamEvent>().Publish(new StorySpamEventArgs(theStory, byUser, storyUrl));

                    _storyRepository.Remove(theStory);

                    unitOfWork.Commit();
                }
            }
        }
        public virtual void StoryPromoted(IStory theStory, IUser byUser)
        {
            Check.Argument.IsNotNull(theStory, "theStory");
            Check.Argument.IsNotNull(byUser, "byUser");

            if (CanChangeScoreForStory(theStory, byUser))
            {
                UserAction reason;
                decimal    score;

                if (theStory.IsPublished())
                {
                    score  = _userScoreTable.PublishedStoryPromoted;
                    reason = UserAction.PublishedStoryPromoted;
                }
                else
                {
                    score  = _userScoreTable.UpcomingStoryPromoted;
                    reason = UserAction.UpcomingStoryPromoted;
                }

                byUser.IncreaseScoreBy(score, reason);
            }
        }