示例#1
0
        public void Delete(Vote vote)
        {
            // Delete any points associated with this vote
            _membershipUserPointsService.Delete(PointsFor.Vote, vote.Id);

            // Delete the vote
            _voteRepository.Delete(vote);
        }
示例#2
0
        public void Delete(Vote vote)
        {
            // Delete any points associated with this vote
            _membershipUserPointsService.Delete(PointsFor.Vote, vote.Id);

            // Delete the vote
            _context.Vote.Remove(vote);
        }
示例#3
0
 public void Update(Vote item)
 {
     // Check there's not an object with same identifier already in context
     if (_context.Vote.Local.Select(x => x.Id == item.Id).Any())
     {
         throw new ApplicationException("Object already exists in context - you do not need to call Update. Save occurs on Commit");
     }
     _context.Entry(item).State = EntityState.Modified;    
 }
示例#4
0
        /// <summary>
        /// Add a new vote
        /// </summary>
        /// <param name="vote"></param>
        /// <returns></returns>
        public Vote Add(Vote vote)
        {
            var e = new VoteEventArgs {Vote = vote, Api = _api};
            EventManager.Instance.FireBeforeVoteMade(this, e);

            if (!e.Cancel)
            {
                _voteRepository.Add(vote);

                EventManager.Instance.FireAfterVoteMade(this, new VoteEventArgs {Vote = vote, Api = _api});
            }

            return vote;
        }
示例#5
0
        /// <summary>
        /// Add a new vote
        /// </summary>
        /// <param name="vote"></param>
        /// <returns></returns>
        public Vote Add(Vote vote)
        {

            var e = new VoteEventArgs {Vote = vote};
            EventManager.Instance.FireBeforeVoteMade(this, e);

            if (!e.Cancel)
            {
                _context.Vote.Add(vote);

                EventManager.Instance.FireAfterVoteMade(this, new VoteEventArgs {Vote = vote});
            }

            return vote;
        }
示例#6
0
 public void Delete(Vote vote)
 {
     _voteRepository.Delete(vote);
 }
示例#7
0
 public void Delete(Vote item)
 {
     _context.Vote.Remove(item);
 }
示例#8
0
 public Vote Add(Vote item)
 {
     _context.Vote.Add(item);
     return item;
 }
        public void AfterVoteMade()
        {
            var voteRepository = Substitute.For<IVoteRepository>();
            var voteService = new VoteService(voteRepository, _api);

            EventManager.Instance.AfterVoteMade += EventManagerInstanceAfterVoteMade;

            var vote = new Vote { Amount = 1 };

            _eventTestStr = string.Empty;
            voteService.Add(vote);

            Assert.IsTrue(_eventTestStr == TestString);
            EventManager.Instance.AfterVoteMade -= EventManagerInstanceAfterVoteMade;
        }
        public void BeforeVoteMadeCancel()
        {
            var voteRepository = Substitute.For<IVoteRepository>();
            var voteService = new VoteService(voteRepository, _api);

            EventManager.Instance.BeforeVoteMade += EventManagerInstanceBeforeVoteMadeCancel;

            var vote = new Vote { Amount = 999 };

            _eventTestStr = string.Empty;
            voteService.Add(vote);

            voteRepository.DidNotReceive().Update((Arg.Is<Vote>(x => x.Amount == 999)));
            EventManager.Instance.BeforeVoteMade -= EventManagerInstanceBeforeVoteMadeCancel;
        }
        public void BeforeVoteMadeAllow()
        {
            var voteRepository = Substitute.For<IVoteRepository>();
            var voteService = new VoteService(voteRepository, _api);

            EventManager.Instance.BeforeVoteMade += EventManagerInstanceBeforeVoteMadeAllow;

            var vote = new Vote { Amount = 1 };

            _eventTestStr = string.Empty;
            voteService.Add(vote);

            voteRepository.Received().Add((Arg.Is<Vote>(x => x.Amount == 1)));
            EventManager.Instance.BeforeVoteMade -= EventManagerInstanceBeforeVoteMadeAllow;
        }
示例#12
0
        private void MarkPostUpOrDown(Post post, MembershipUser postWriter, MembershipUser voter, PostType postType)
        {
            // Check this user is not the post owner
            if (voter.Id != postWriter.Id)
            {
                // Not the same person, now check they haven't voted on this post before
                if (post.Votes.All(x => x.User.Id != LoggedOnUser.Id))
                {

                    // Points to add or subtract to a user
                    var usersPoints = (postType == PostType.Negative) ?
                                        (-SettingsService.GetSettings().PointsDeductedNagativeVote) : (SettingsService.GetSettings().PointsAddedPostiveVote);

                    // Update the users points who wrote the post
                    _membershipUserPointsService.Add(new MembershipUserPoints { Points = usersPoints, User = postWriter });

                    // Update the post with the new vote of the voter
                    var vote = new Vote
                    {
                        Post = post,
                        User = voter,
                        Amount = (postType == PostType.Negative) ? (-1) : (1),
                        VotedByMembershipUser = LoggedOnUser,
                        DateVoted = DateTime.UtcNow
                    };
                    _voteService.Add(vote);

                    // Update the post with the new points amount
                    var newPointTotal = (postType == PostType.Negative) ? (post.VoteCount - 1) : (post.VoteCount + 1);
                    post.VoteCount = newPointTotal;
                }
            }
        }
示例#13
0
        private void MarkPostUpOrDown(Post post, MembershipUser postWriter, MembershipUser voter, PostType postType)
        {
            var settings = SettingsService.GetSettings();
            // Check this user is not the post owner
            if (voter.Id != postWriter.Id)
            {
                // Not the same person, now check they haven't voted on this post before
                var votes = post.Votes.Where(x => x.VotedByMembershipUser.Id == LoggedOnReadOnlyUser.Id).ToList();
                if (votes.Any())
                {
                    // Already voted, so delete the vote and remove the points
                    var votesToDelete = new List<Vote>();
                    votesToDelete.AddRange(votes);
                    foreach (var vote in votesToDelete)
                    {
                        _voteService.Delete(vote);
                    }

                    // Update the post with the new points amount
                    var newPointTotal = (postType == PostType.Negative) ? (post.VoteCount + 1) : (post.VoteCount - 1);
                    post.VoteCount = newPointTotal;
                }
                else
                {
                    // Points to add or subtract to a user
                    var usersPoints = (postType == PostType.Negative) ? (-settings.PointsDeductedNagativeVote) : (settings.PointsAddedPostiveVote);

                    // Update the post with the new vote of the voter
                    var vote = new Vote
                    {
                        Post = post,
                        User = postWriter,
                        Amount = (postType == PostType.Negative) ? (-1) : (1),
                        VotedByMembershipUser = voter,
                        DateVoted = DateTime.UtcNow
                    };
                    _voteService.Add(vote);

                    // Update the users points who wrote the post
                    _membershipUserPointsService.Add(new MembershipUserPoints
                    {
                        Points = usersPoints,
                        User = postWriter,
                        PointsFor = PointsFor.Vote,
                        PointsForId = vote.Id
                    });

                    // Update the post with the new points amount
                    var newPointTotal = (postType == PostType.Negative) ? (post.VoteCount - 1) : (post.VoteCount + 1);
                    post.VoteCount = newPointTotal;
                }
            }
        }