public void Add_Normal_Conditions() { var repo = new VoteRepository(); var vote = new Vote(); vote.OptionId = 2; vote.SurveyId = 3; repo.Add(vote); }
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)); }
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); } }
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); }
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.")); } }
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); } } }