コード例 #1
0
        private int CalculateSeatsForPartyProfile(Election election, PartyProfile partyProfile)
        {
            decimal totalVotes = election.PartyProfiles.Sum(party => party.Votes);
            decimal votes      = partyProfile.Votes / totalVotes;

            return((int)decimal.Round(votes * election.DistributableSeats));
        }
コード例 #2
0
        public IActionResult AddResult(int electionid, int partyid, PartyProfileViewModel partyProfile)
        {
            Election election = electionCollection.GetElectionByID(electionid);
            Party    party    = partyCollection.GetPartyByID(partyid);

            ViewBag.Election = election;
            ViewBag.Party    = party;

            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                PartyProfile newPartyProfile = new PartyProfile
                {
                    Votes = partyProfile.Votes,
                    Party = party
                };
                election.PartyProfiles.Add(newPartyProfile);
                newPartyProfile.Seats = CalculateSeatsForPartyProfile(election, newPartyProfile);
                electionCollection.CreatePartyProfile(election.ID, newPartyProfile);
                return(RedirectToAction("Info", "Election", new { id = election.ID }));
            }
            catch (CreatingElectionFailedException exception)
            {
                ModelState.AddModelError("", exception.Message);
                return(View());
            }
        }
コード例 #3
0
 public void CreatePartyProfile(int id, PartyProfile partyProfile)
 {
     electionRepository.CreatePartyProfile(id, DTOConvertor.GetPartyProfileDTO(partyProfile));
 }