public String CreateVote(CreateVoteModel createVoteModel) { DatabaseService dbService = new DatabaseService(); dbService.Vote(createVoteModel); return("Point Gemt!"); }
public void Vote(CreateVoteModel createVoteModel) { using (DB_YoungEnterpriseContext databaseContext = GetConnection()) { var service = new UserService(); int questionID = GetQuestionID(createVoteModel.FldQuestiontext); int judgePairID = GetJudgePairID(createVoteModel.FldJudgeUsername); // todo validate above + FldTeamName // New Vote and get voteID returned int voteID = 0; TblVote vote = TryFindVote(questionID, judgePairID, createVoteModel.FldTeamName); if (vote == null) { voteID = CreateVote(judgePairID, createVoteModel.FldTeamName, createVoteModel.FldPoints); CreateVoteAnswer(questionID, voteID); } else { UpdateVote(vote.FldVoteId, judgePairID, createVoteModel.FldTeamName, createVoteModel.FldPoints); } // Just for test of exceptionhandling. TODO remove throw new Exception("øv"); } }
public IHttpActionResult Create(CreateVoteModel model) { //var data = new CreateVoteHandler(_voteService).Handle(model); //return Ok(); return(AsResult(Handler.Get <CreateVoteHandler>().Handle(model))); }
public async Task <IActionResult> Create([FromBody, BindRequired] CreateVoteModel createVoteModel) { if (!ModelState.IsValid || createVoteModel == null) { return(BadRequest(ModelState)); } var user = await _userRepository.GetByIdAsync(createVoteModel.CreatedById); if (user == null) { return(BadRequest()); } var vote = await _cakelistService.VoteOnCakeRequestAsync(createVoteModel.CakeRequestId, user); return(CreatedAtAction("GetAllById", new { Id = vote.Id }, vote)); }
public void FindQuestionAndVotes() { var eventID = service.CreateEvent(DateTime.Now); // Judges service.CreateJudge(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "A"); service.CreateJudge(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "B"); service.CreateJudge(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "C"); service.CreateJudge(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "D"); service.CreateJudgePairs(); var judgePairs = service.GetAllJudgePairs(); Assert.AreEqual(2, judgePairs.Count()); var pair1 = judgePairs[0]; var pair2 = judgePairs[1]; // School var school = service.CreateSchool(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "Business College Syd"); // Teams service.CreateTeam("EasyOn", school.FldSchoolId, "Trade and Skills", new byte[10]); service.CreateTeam("Two", school.FldSchoolId, "Trade and Skills", new byte[10]); // Questions (already setup) var questions = service.GetAllQuestions(); var question1 = questions[0]; // Votes var voteModel = new CreateVoteModel() { FldJudgeUsername = service.GetJudgeByID(pair1.FldJudgeIda).FldJudgeUsername, FldPoints = 2, FldQuestiontext = question1.FldQuestionText, FldTeamName = "EasyOn" }; service.Vote(voteModel); List <TblVoteAnswer> voteAnswer = service.FindQuestionsAndVotes("Report", "Trade and Skills", pair1.FldJudgePairId, "EasyOn"); Assert.AreEqual(2, voteAnswer.Count); Assert.AreEqual(1, voteAnswer.Where(a => a.Points == 0).Count()); Assert.AreEqual(1, voteAnswer.Where(a => a.Points == 2).Count()); }
public void FindTeamResultsTest() { var eventID = service.CreateEvent(DateTime.Now); // Judges service.CreateJudge(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "A"); service.CreateJudge(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "B"); service.CreateJudge(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "C"); service.CreateJudge(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "D"); service.CreateJudgePairs(); var judgePairs = service.GetAllJudgePairs(); Assert.AreEqual(2, judgePairs.Count()); var pair1 = judgePairs[0]; var pair2 = judgePairs[1]; // School var school = service.CreateSchool(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "Business College Syd"); // Teams service.CreateTeam("EasyOn", school.FldSchoolId, "Trade and Skills", new byte[10]); service.CreateTeam("Two", school.FldSchoolId, "Trade and Skills", new byte[10]); // Questions (already setup) var questions = service.GetAllQuestions(); var question1 = questions[0]; // Votes var voteModel = new CreateVoteModel() { FldJudgeUsername = service.GetJudgeByID(pair1.FldJudgeIda).FldJudgeUsername, FldPoints = 2, FldQuestiontext = question1.FldQuestionText, FldTeamName = "EasyOn" }; service.Vote(voteModel); List <TeamResultModel> teamResults = service.FindTeamResults(); Assert.AreEqual(2, teamResults.Count); Assert.AreEqual(2 * question1.FldQuestionModifier, teamResults[0].OverallPoints); }
public IActionResult Create([FromBody] CreateVoteModel model) { try { var vote = _voteService.Create(model.OptionId, int.Parse(User.Identity.Name)); // var topicResource = _mapper.Map<TopicResourceModel>(topic); if (vote != null) { return(Ok(new { message = "Voted" })); } else { return(BadRequest(new { message = "Sorry, you've already voted on this topic" })); } } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public void VoteTest() { var eventID = service.CreateEvent(DateTime.Now); // Judges service.CreateJudge(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "A"); service.CreateJudge(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "B"); service.CreateJudge(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "C"); service.CreateJudge(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "D"); service.CreateJudgePairs(); var judgePairs = service.GetAllJudgePairs(); Assert.AreEqual(2, judgePairs.Count()); var pair1 = judgePairs[0]; var pair2 = judgePairs[1]; // School var school = service.CreateSchool(eventID, "*****@*****.**", userService.HashPassword("*****@*****.**", "12345"), "Business College Syd"); // Teams service.CreateTeam("EasyOn", school.FldSchoolId, "Trade and Skills", new byte[10]); service.CreateTeam("Two", school.FldSchoolId, "Trade and Skills", new byte[10]); // Questions (already setup) var questions = service.GetAllQuestions(); var question1 = questions[0]; var question2 = questions[1]; // Do var voteModel = new CreateVoteModel() { FldJudgeUsername = service.GetJudgeByID(pair1.FldJudgeIda).FldJudgeUsername, FldPoints = 10, FldQuestiontext = question1.FldQuestionText, FldTeamName = "EasyOn" }; service.Vote(voteModel); var voteModel2 = new CreateVoteModel() { FldJudgeUsername = service.GetJudgeByID(pair1.FldJudgeIda).FldJudgeUsername, FldPoints = 3, FldQuestiontext = question2.FldQuestionText, FldTeamName = "EasyOn" }; service.Vote(voteModel2); // Assertions var vote1 = service.FindJudgePairVotes(question1.FldQuestionId, pair1.FldJudgePairId, "EasyOn"); Assert.IsNotNull(vote1); Assert.AreEqual(10, vote1.FldPoints); var vote2 = service.FindJudgePairVotes(question2.FldQuestionId, pair1.FldJudgePairId, "EasyOn"); Assert.IsNotNull(vote2); Assert.AreEqual(3, vote2.FldPoints); // Revote voteModel.FldPoints = 5; service.Vote(voteModel); // Assertions var vote3 = service.FindJudgePairVotes(question1.FldQuestionId, pair1.FldJudgePairId, "EasyOn"); Assert.IsNotNull(vote3); Assert.AreEqual(5, vote3.FldPoints); }