Esempio n. 1
0
        public void Add_Normal_Conditions()
        {
            var repo = new VoteRepository();
            var vote = new Vote();

            vote.OptionId = 2;
            vote.SurveyId = 3;
            repo.Add(vote);
        }
Esempio n. 2
0
        private static async Task <Vote> CreateVote(VoteRepository repository, int warId)
        {
            var request = CreateTestVote();
            await repository.Add(warId, request);

            var votes = await repository.Get(warId, request.MatchId);

            VerifyRequestInVotesCollection(votes, request);
            return(votes.Single(x => x.MatchId == request.MatchId));
        }
Esempio n. 3
0
 public void Add_And_Presist_Changes_Should_Succeed()
 {
     using (BeginTransaction())
     {
         var vote = CreateNewStoryVote();
         _voteRepository.Add(vote);
         Assert.Equal(EntityState.Added, vote.EntityState);
         _database.SubmitChanges();
         Assert.Equal(EntityState.Unchanged, vote.EntityState);
     }
 }
Esempio n. 4
0
        public void Delete_Normal_Conditions()
        {
            var repo = new VoteRepository();
            var vote = new Vote();

            vote.OptionId = 2;
            vote.SurveyId = 3;
            var count = repo.GetAll().Count();

            repo.Add(vote);
            repo.Delete(vote);
            Assert.IsTrue(repo.GetAll().Count() == count);
        }
Esempio n. 5
0
        public async Task <IActionResult> Submit(VoteInput input)
        {
            var token = HttpContext.Request.Headers["Authorization"].Last().Split(" ").Last();
            var roles = new List <string>()
            {
                "User"
            };

            var handler = new JwtSecurityTokenHandler();
            var sub     = handler.ReadJwtToken(token).Payload.Sub;

            if (RoleService.CheckRoles(token, roles, _userManager))
            {
                var vote = VoteInputConverter.Convert(input);

                var detailsRepo     = new UserDetailsRepository();
                var voteRecordsRepo = new VoteRecordRepository();

                var detailsId = detailsRepo.GetByUserId(sub).Id;
                var surveyId  = vote.SurveyId;

                if (voteRecordsRepo.GetAll().Count(x => x.UserDetailsId == detailsId && x.SurveyId == surveyId) == 0)
                {
                    _repository.Add(vote);



                    var record = new VoteRecord(surveyId, detailsId);
                    voteRecordsRepo.Add(record);

                    return(CreatedAtAction("Submit", vote));
                }

                return(BadRequest("You already voted"));
            }
            else
            {
                return(BadRequest("Only Users can vote."));
            }
        }
Esempio n. 6
0
        internal void Vote(string debate_id, string voteCasted, string userVoting)
        {
            Vote vote = new DatabaseAccess.Vote();

            vote.debate_id     = int.Parse(debate_id);
            vote.user_username = userVoting;
            if (voteCasted == "pro")
            {
                vote.vote_pro = true;
            }
            else
            {
                vote.vote_pro = false;
            }

            try
            {
                Vote debateVote = _voteRepository.GetDebateVote(int.Parse(debate_id), userVoting);
                if (debateVote.vote_pro == vote.vote_pro)
                {
                    _voteRepository.Delete(debateVote.vote_id);
                }
                else
                {
                    debateVote.vote_pro = vote.vote_pro;
                    _voteRepository.Update(debateVote);
                }
            }
            catch (VoteException vex)
            {
                if (vex.Message == "333")
                {
                    _voteRepository.Add(vote);
                }
            }
        }