Esempio n. 1
0
 private Vote(Guid userId, Comment comment, VoteTypeEnum voteType)
 {
     UserId    = userId;
     CommentId = comment.Id;
     VoteType  = voteType;
     CreatedOn = DateTime.UtcNow;
 }
Esempio n. 2
0
 private Vote(Guid userId, Answer answer, VoteTypeEnum voteType)
 {
     UserId    = userId;
     AnswerId  = answer.Id;
     VoteType  = voteType;
     CreatedOn = DateTime.UtcNow;
 }
Esempio n. 3
0
 private Vote(Guid userId, Question question, VoteTypeEnum voteType)
 {
     UserId     = userId;
     QuestionId = question.Id;
     VoteType   = voteType;
     CreatedOn  = DateTime.UtcNow;
 }
Esempio n. 4
0
 public async Task CalculateAsync(Guid userId, VoteTypeEnum voteType)
 {
     await _userRepository.CalculatePointsAsync(
         userId,
         voteType == VoteTypeEnum.Upvote
         ?_limits.UpvotePoints
         : _limits.DownvotePoints);
 }
 private CongressVote createVote(CongressVoting voting, int citizenID, VoteTypeEnum voteType)
 {
     return(new CongressVote()
     {
         VoteTypeID = (int)voteType,
         CongressVoting = voting,
         CitizenID = citizenID
     });
 }
        public CongressVote AddVote(CongressVoting voting, Citizen citizen, VoteTypeEnum voteType)
        {
            CongressVote vote = createVote(voting, citizen.ID, voteType);

            congressVotingRepository.AddVote(vote);
            congressVotingRepository.SaveChanges();

            return(vote);
        }
Esempio n. 7
0
 public static Vote CreateVote(Guid userId, IVoteable voteable, VoteTypeEnum voteType)
 {
     return(voteable switch
     {
         Question question => new Vote(userId, question, voteType),
         Answer answer => new Vote(userId, answer, voteType),
         Comment comment => new Vote(userId, comment, voteType),
         _ => throw new ArgumentException()
     });
        private ActionResult Vote(int congressVotingID, VoteTypeEnum voteType)
        {
            var voting = congressVotingRepository.GetById(congressVotingID);
            var entity = SessionHelper.CurrentEntity;

            if (entity.Citizen == null)
            {
                AddError("Wrong entity");
                return(RedirectToAction("ViewVoting", new { votingID = congressVotingID }));
            }

            var citizen = entity.Citizen;

            if (voting.CommentRestrictionID != (int)CommentRestrictionEnum.CitizenCanComment && voting.Country.Congressmen.Any(c => c.CitizenID == citizen.ID) == false)
            {
                AddError("You cannot vote on this!");
                return(RedirectToAction("ViewVoting", new { votingID = congressVotingID }));
            }

            if (congressVotingService.CanVote(citizen, voting) == false)
            {
                AddError("You cannot vote!");
                return(RedirectToAction("ViewVoting", new { votingID = congressVotingID }));
            }

            if (voting.GetTimeLeft(GameHelper.CurrentDay).TotalSeconds <= 0)
            {
                AddError("You cannot vote!");
                return(RedirectToAction("ViewVoting", new { votingID = congressVotingID }));
            }

            congressVotingService.AddVote(voting, citizen, voteType);

            AddInfo("You had voted");
            return(RedirectToAction("ViewVoting", new { votingID = congressVotingID }));
        }
Esempio n. 9
0
 public VoteBuilder SetupValidDownvote()
 {
     _voteType = VoteTypeEnum.Downvote;
     return(this);
 }