public ActionResult VoteCongressCandidate(int candidateID) { var candidate = congressCandidateVotingRepository.GetCandidate(candidateID); var voting = candidate.CongressCandidateVoting; if (voting.Is(VotingStatusEnum.NotStarted)) { return(RedirectBackWithError("Voting is not started yet!")); } else if (voting.Is(VotingStatusEnum.Finished)) { return(RedirectBackWithError("Voting was finished")); } var entity = SessionHelper.CurrentEntity; if (entity.Is(EntityTypeEnum.Citizen) == false) { return(RedirectBackWithError("You are not a citizen")); } var citizen = SessionHelper.LoggedCitizen; if (voting.HasVoted(citizen)) { return(RedirectBackWithError("You alerady voted!")); } congressCandidateService.VoteOnCongressCandidate(citizen, candidate); AddInfo(string.Format("You voted on {0}.", candidate.Citizen.Entity.Name)); return(RedirectBack()); }
public ActionResult AcceptCongressCandidate(int candidateID) { var entity = SessionHelper.CurrentEntity; if (!entity.Is(EntityTypeEnum.Citizen)) { return(RedirectToHomeWithError()); } var citizen = entity.Citizen; if (citizen.PartyMember == null) { return(RedirectToHomeWithError()); } var candidate = congressCandidateVotingRepository.GetCandidate(candidateID); var party = candidate.Party; if (partyService.CanAcceptCongressCandidates(citizen, party)) { partyService.AcceptCongressCandidate(candidate); AddInfo(string.Format("You accepted {0} as congress candidate", candidate.Citizen.Entity.Name)); return(RedirectToAction("CongressCandidates", new { partyID = party.ID })); } return(RedirectToHomeWithError()); }
public void ProcessDayChange(int newDay) { var countries = countryRepository.GetAll(); foreach (var country in countries) { var policy = country.CountryPolicy; var congressCandidateVoting = congressCandidateVotingRepository.GetLastVotingForCountry(country.ID); if (congressCandidateVoting.VotingStatusID == (int)VotingStatusEnum.NotStarted) { if (congressCandidateVoting.CongressCandidates.Count == 0) { congressCandidateVoting.VotingDay = GameHelper.CurrentDay + 7; } else if (newDay >= congressCandidateVoting.VotingDay) { DismissCongressmen(country); congressCandidateVoting.VotingStatusID = (int)VotingStatusEnum.Ongoing; } } else if (congressCandidateVoting.VotingStatusID == (int)VotingStatusEnum.Ongoing) { var RegionsOfCandidates = congressCandidateVoting .CongressCandidates .Where(c => c.CongressCandidateVoting.CountryID == country.ID) .Where(c => c.CongressCandidateStatusID == (int)CongressCandidateStatusEnum.Approved) .GroupBy(c => c.RegionID) .ToList(); foreach (var region in RegionsOfCandidates) { var votes = region .Select(c => new { CandidateID = c.ID, VoteCount = c.CongressCandidateVotes.Count() }) .OrderByDescending(v => v.VoteCount) .ThenByDescending(v => v.CandidateID) // candidates which candidated first can win with candidate with same amount of votes .ToList(); for (int i = 0; i < Constants.ElectedCongressCandidatesByRegion && i < votes.Count; ++i) { var candidate = congressCandidateVotingRepository.GetCandidate(votes[i].CandidateID); country.Congressmen.Add(createCongressman(candidate.Citizen.ID, country.ID)); var gold = GetGoldForCadency(policy.CongressCadenceLength); citizenService.ReceiveCongressMedal(candidate.Citizen, gold); } } congressCandidateVoting.VotingStatusID = (int)VotingStatusEnum.Finished; if (RegionsOfCandidates.Count == 0) { CreateNewCongressCandidateVoting(country, newDay + 7); } else { CreateNewCongressCandidateVoting(country, newDay + policy.CongressCadenceLength); } } } congressCandidateVotingRepository.SaveChanges(); }