Esempio n. 1
0
        public Models.VoteResults GetModel(VoteResult voteResult)
        {
            var electionResult = new VoteResults();

            if (voteResult.RankingVoteId != null)
            {
                electionResult.RankingVoteId   = voteResult.RankingVoteId;
                electionResult.RankingVoteItem = RankingVoteTicketBuilder.GetModel(voteResult.RankingVote);
                electionResult.Ranking         = voteResult.Ranking;
            }
            if (voteResult.SingleVote != null)
            {
                electionResult.SingleVoteId   = voteResult.SingleVoteId;
                electionResult.SingleVoteItem = SingleVoteTicketBuilder.GetModel(voteResult.SingleVote);
                electionResult.VotedYes       = voteResult.VoteYes;
                electionResult.VotedNo        = voteResult.VoteNo;
            }
            if (voteResult.MultipleVote != null)
            {
                electionResult.MultipleVoteId   = voteResult.MultipleVoteId;
                electionResult.MultipleVoteItem = MultiVoteTicketBuilder.GetModel(voteResult.MultipleVote);
                electionResult.VotedFor         = voteResult.VotedFor;
            }
            return(electionResult);
        }
Esempio n. 2
0
 // GET: Vote
 public ViewResult Index(VoteResults votes, string returnUrl)
 {
     return(View(new VotesViewModel
     {
         Votes = votes,
         ReturnUrl = returnUrl
     }));
 }
 public void Can_Remove_Person_From_Vote_List()
 {
     votes = new VoteResults();
     sutController.AddVote(votes, 1, "");
     sutController.RemoveVote(votes, 1, "");
     // Assert
     Assert.AreEqual(votes.Votes.Count(), 0);
 }
 public void Can_Add_Person_To_Vote_List()
 {
     votes = new VoteResults();
     sutController.AddVote(votes, 1, "");
     // Assert
     Assert.AreEqual(votes.Votes.Count(), 1);
     Assert.AreEqual(votes.Votes.ToArray()[0].PersonId, 1);
 }
Esempio n. 5
0
        public void Can_Save_Votes_After_Checkout()
        {
            var votes = new VoteResults();

            sutVoteController.AddVote(votes, 1, "");
            sutVoteController.Checkout(votes);
            sutDB.Verify(m => m.SaveVote(It.IsAny <Vote>()));
        }
 public void Cannot_Add_Votes_More_Expensive_Than_Balance()
 {
     votes = new VoteResults();
     sutController.AddVote(votes, 1, "");
     sutController.AddVote(votes, 2, "");
     sutController.AddVote(votes, 3, "");
     // Assert
     Assert.AreEqual(votes.Votes.Count(), 2);
 }
 public void Cannot_Remove_Vote_Twice()
 {
     votes = new VoteResults();
     sutController.AddVote(votes, 1, "");
     sutController.RemoveVote(votes, 1, "");
     sutController.RemoveVote(votes, 1, "");
     // Assert
     Assert.AreEqual(votes.Votes.Count(), 0);
 }
        public void Can_View_Cart_Contents()
        {
            votes = new VoteResults();
            VoteController target = new VoteController(null, null, null);
            VotesViewModel result = (VotesViewModel)target.Index(votes, "myUrl").ViewData.Model;

            // Assert
            Assert.AreSame(result.Votes, votes);
            Assert.AreEqual(result.ReturnUrl, "myUrl");
        }
 public void Init()
 {
     p1 = new Person {
         PersonId = 1, Name = "P1"
     };
     p2 = new Person {
         PersonId = 2, Name = "P2"
     };
     sut = new VoteResults();
 }
Esempio n. 10
0
        public RedirectToRouteResult RemoveVote(VoteResults votes, int personId, string returnUrl)
        {
            Person person = repository.Table.FirstOrDefault(p => p.PersonId == personId);

            if (person != null)
            {
                votes.RemoveVote(person);
            }
            return(RedirectToAction("Index", new { returnUrl }));
        }
Esempio n. 11
0
        public ActionResult AddVote(VoteResults votes, int personId, string returnUrl)
        {
            Person person = repository.Table.FirstOrDefault(p => p.PersonId == personId);

            if (person != null)
            {
                votes.AddVote(person);
            }
            //return RedirectToAction("Index", new {returnUrl});
            return(PartialView("Summary", votes));
        }
Esempio n. 12
0
        public void Cannot_Vote_After_Checkout()
        {
            var votes = new VoteResults();

            sutWeekProvider.SetupSequence(m => m.GetWeek())
            .Returns(1).Returns(1);
            sutVoteController.AddVote(votes, 1, "");
            sutVoteController.Checkout(votes);
            sutVoteController.AddVote(votes, 2, "");
            sutVoteController.Checkout(votes);
            sutDB.Verify(m => m.SaveVote(It.IsAny <Vote>()), Times.Once);
        }
Esempio n. 13
0
        public void Can_Vote_Next_Week()
        {
            sutWeekProvider.SetupSequence(m => m.GetWeek())
            .Returns(1).Returns(2);
            var votes = new VoteResults();

            votesList = new List <Vote>();
            sutVoteController.AddVote(votes, 1, "");
            sutVoteController.Checkout(votes);
            sutVoteController.AddVote(votes, 2, "");
            sutVoteController.Checkout(votes);
            sutDB.Verify(m => m.SaveVote(It.IsAny <Vote>()), Times.Exactly(2));
        }
        public object BindModel(ControllerContext controllerContext, ModelBindingContext
                                bindingContext)
        {
            // get the Cart from the session
            VoteResults votes = (VoteResults)controllerContext.HttpContext.Session[sessionKey];

            // create the Cart if there wasn't one in the session data
            if (votes == null)
            {
                votes = new VoteResults();
                controllerContext.HttpContext.Session[sessionKey] = votes;
            }
            // return the cart
            return(votes);
        }
Esempio n. 15
0
        private static void OnVote(CommandData commandData)
        {
            // converts a string like "$VOTE 2" to an integer 2.
            if (int.TryParse(commandData.Command.Split(' ').ElementAtOrDefault(1), out int voteFor) &&
                1 <= voteFor && voteFor <= VoteCount)    // If the number is a valid map to vote for.
            {
                // Test if the player already voted for a map. If they did, update the map they are voting for.
                for (int i = 0; i < VoteResults.Count; i++)
                {
                    if (commandData.ChatIdentity.CompareIdentities(VoteResults[i].ChatIdentity))
                    {
                        Console.WriteLine(string.Format("Player #{0} changing their vote to: {1}", i, voteFor));
                        VoteResults[i].VotingFor = voteFor;
                        return;
                    }
                }

                // If they didn't already vote for a map, add their vote to the VoteResults list.

                Console.WriteLine(string.Format("New vote from player #{0}: {1}", VoteResults.Count, voteFor));
                VoteResults.Add(new Vote(voteFor, commandData.ChatIdentity));
            }
        }
Esempio n. 16
0
        public ViewResult Checkout(VoteResults votes)
        {
            var userName    = UserProvider.GetUserName(this);
            var currentWeek = WeekProvider.GetWeek();

            if (repository.Votes.Any(x => x.Week == currentWeek && x.UserName == userName))
            {
                return(View(false));
            }
            repository.SaveVote(new Vote {
                UserName = userName, Week = currentWeek
            });
            var voteId = repository.Votes.FirstOrDefault(x => x.Week == currentWeek && x.UserName == userName).VoteId;

            foreach (var vote in votes.Votes)
            {
                repository.SaveVoteItem(new VoteItem()
                {
                    PersonId = vote.PersonId, VoteId = voteId
                });
            }
            return(View(true));
        }
Esempio n. 17
0
        public static Map VoteForMap(CustomGame cg, Map[] maps)
        {
            Random rnd = new Random();

            int[] votemap = new int[VoteCount]; // The index of maps that can be voted for. 3 is the amount of maps chosen that can be voted for.
            for (int i = 0; i < votemap.Length; i++)
            {
                int choose;
                while (true)
                {
                    // Make sure there are no duplicates when choosing the next map to be added to the votemap array
                    choose = rnd.Next(maps.Length);
                    if (votemap.Contains(choose))
                    {
                        continue;
                    }
                    break;
                }
                votemap[i] = choose;
            }

            // Send the maps to vote for to the chat.
            cg.Chat.SendChatMessage(FormatMessage(
                                        "Vote for map! (15 seconds)",
                                        maps[votemap[0]].ShortName + " - $VOTE 1",
                                        maps[votemap[1]].ShortName + " - $VOTE 2",
                                        maps[votemap[2]].ShortName + " - $VOTE 3"));

            // Listen to the "$VOTE" command for 15 seconds.
            cg.Commands.ListenTo.Add(VoteCommand);
            Thread.Sleep(15000);
            cg.Commands.ListenTo.Remove(VoteCommand);
            // Get results
            int[] results = new int[VoteCount]
            {
                VoteResults.Count(vr => vr.VotingFor == 1),
                VoteResults.Count(vr => vr.VotingFor == 2),
                VoteResults.Count(vr => vr.VotingFor == 3)
            };

            int winningmap = votemap[Array.IndexOf(results, results.Max())];

            // Dispose all chat identities.
            foreach (Vote voteResult in VoteResults)
            {
                voteResult.ChatIdentity.Dispose();
            }
            VoteResults = new List <Vote>();

            // Print the results to the chat
            string mapResults = String.Format("{0}: {1} votes, {2}: {3} votes, {4}: {5} votes",
                                              maps[votemap[0]].ShortName, results[0],
                                              maps[votemap[1]].ShortName, results[1],
                                              maps[votemap[2]].ShortName, results[2]);

            cg.Chat.SendChatMessage(mapResults);
            Program.Log(mapResults);
            cg.Chat.SendChatMessage("Next map: " + maps[winningmap].ShortName);
            cg.ToggleMap(ToggleAction.DisableAll, maps[winningmap]);

            return(maps[winningmap]);
        }
Esempio n. 18
0
 public PartialViewResult Summary(VoteResults votes)
 {
     return(PartialView(votes));
 }
Esempio n. 19
0
 public void SetVote(VoteResults votestate)
 {
     Vote = votestate;
 }
Esempio n. 20
0
        private ActionResult GetRefreshedRatesHtml(String itemKey)
        {
            VoteResults vr = RatingRepository.GetVoteResults(itemKey);

            return(this.PartialView("RatesPlusMinus", vr));
        }
Esempio n. 21
0
 public void SetVote(VoteResults votestate)
 {
     Vote = votestate;
 }