protected virtual object CreateModelPart(ForumPostVote part, MessageContext messageContext)
        {
            Guard.NotNull(messageContext, nameof(messageContext));
            Guard.NotNull(part, nameof(part));

            var m = new Dictionary <string, object>
            {
                { "ForumPostId", part.ForumPostId },
                { "Vote", part.Vote },
                { "TopicId", part.ForumPost.TopicId },
                { "TopicSubject", part.ForumPost.ForumTopic.Subject.NullEmpty() },
            };

            ApplyCustomerContentPart(m, part, messageContext);

            PublishModelPartCreatedEvent(part, m);

            return(m);
        }
        protected void ArticleLikeDislikeComment(object sender, ActiveEventArgs e)
        {
            int commentId = e.Params["CommentID"].Get<int>();
            int score = e.Params["Score"].Get<int>();
            ForumPost post = ForumPost.SelectByID(commentId);
            if (post.RegisteredUser != null &&
                post.RegisteredUser.Username == Users.LoggedInUserName)
            {
                Node nodeMessage = new Node();
                nodeMessage["Message"].Value =
                    Language.Instance["YouCannotVoteForOwnComments", null, "You cannot vote for your own comments"];
                nodeMessage["Duration"].Value = 2000;
                ActiveEvents.Instance.RaiseActiveEvent(
                    this,
                    "ShowInformationMessage",
                    nodeMessage);
                e.Params["Refresh"].Value = false;
                return;
            }
            ForumPostVote vote = ForumPostVote.SelectFirst(
                Criteria.Eq("User.Username", Users.LoggedInUserName),
                Criteria.ExistsIn(post.ID));
            if (vote != null)
            {
                post.Score -= vote.Score;
            }
            else
            {
                vote = new ForumPostVote();
                vote.ForumPost = post;
                vote.User = User.SelectFirst(Criteria.Eq("Username", Users.LoggedInUserName));
            }
            post.Score += score;
            vote.Score = score;
            vote.Save();
            post.Save();
            e.Params["Refresh"].Value = true;

            // Giving user score
            if (score > 0)
                vote.User.Score += Settings.Instance.Get<int>("PointsForUpVote", 1);
            else
                vote.User.Score += Settings.Instance.Get<int>("PointsForDownVote", -1);
            vote.User.Save();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Update a post vote
 /// </summary>
 /// <param name="postVote">Post vote</param>
 public void UpdatePostVote(ForumPostVote postVote)
 {
     _forumService.UpdatePostVote(postVote);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Delete a post vote
 /// </summary>
 /// <param name="postVote">Post vote</param>
 public void DeletePostVote(ForumPostVote postVote)
 {
     _forumService.DeletePostVote(postVote);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Insert a post vote
 /// </summary>
 /// <param name="postVote">Post vote</param>
 public void InsertPostVote(ForumPostVote postVote)
 {
     _forumService.InsertPostVote(postVote);
 }