Beispiel #1
0
        public void ProcessDayChange(int newDay)
        {
            var parties = partyRepository.GetAll();

            foreach (var party in parties)
            {
                PartyPresidentVoting partyVoting = party.PartyPresidentVotings.Last();

                if (partyVoting.VotingStatusID == (int)VotingStatusEnum.NotStarted)
                {
                    if (partyVoting.PartyPresidentCandidates.Count == 0)
                    {
                        partyVoting.VotingDay = GameHelper.CurrentDay + 7;
                    }
                    else if (newDay >= partyVoting.VotingDay)
                    {
                        partyVoting.VotingStatusID = (int)VotingStatusEnum.Ongoing;
                    }
                }
                else if (partyVoting.VotingStatusID == (int)VotingStatusEnum.Ongoing)
                {
                    var votes = partyVoting.PartyPresidentVotes
                                .Where(v => v.PartyPresidentCandidate.Citizen.PartyMember != null)
                                .Where(v => v.PartyPresidentCandidate.Citizen.PartyMember.PartyID == party.ID)
                                .GroupBy(v => v.PartyPresidentCandidateID)
                                .Select(v => new { CandidateID = v.Key, VoteCount = v.Count() })
                                .OrderByDescending(v => v.VoteCount)
                                .ToList();

                    if (votes.Count == 0)
                    {
                        partyVoting.VotingStatusID = (int)VotingStatusEnum.Finished;
                        CreateNewPresidentVoting(party, newDay + 7);
                    }



                    else if (votes.Count != 1 && votes[0].VoteCount == votes[1].VoteCount)
                    {
                        partyVoting.VotingStatusID = (int)VotingStatusEnum.Finished;
                        CreateNewPresidentVoting(party, newDay + 7);
                    }
                    else
                    {
                        DismissPresidentAndManagers(party);

                        var policy = party.Country.CountryPolicy;

                        var candidate = partyRepository.GetPartyPresidentCandidate(votes[0].CandidateID);
                        candidate.Citizen.PartyMember.PartyRoleID = (int)PartyRoleEnum.President;

                        CreateNewPresidentVoting(party, newDay + policy.PartyPresidentCadenceLength);
                        partyVoting.VotingStatusID = (int)VotingStatusEnum.Finished;
                    }
                }
            }

            partyRepository.SaveChanges();
        }
        public IEnumerable <PartyTypeModel> GetAll()
        {
            var party = partyRepository.GetAll();

            Mapper.Initialize(map => { map.CreateMap <PartyType, PartyTypeModel>(); });
            var partyData = Mapper.Map <IEnumerable <PartyType>, IEnumerable <PartyTypeModel> >(party);

            return(partyData);
        }
Beispiel #3
0
        public ICollection <PartyDto> GetAllParties()
        {
            var parties = _partyRepository.GetAll();

            if (!parties.IsNullOrEmpty())
            {
                ICollection <PartyDto> partyDtos = new LinkedList <PartyDto>();
                PartyDto partyDto = null;

                foreach (Party party in parties)
                {
                    partyDto             = new PartyDto();
                    partyDto.Id          = party.Id;
                    partyDto.DisplayName = party.DisplayName;

                    partyDtos.Add(partyDto);
                }

                return(partyDtos);
            }

            return(null);
        }
        public async Task <IEnumerable <PartyViewModel> > GetAll(string name, bool withMembers = false, bool withActiveMembers = false)
        {
            var parties = await _partyRepository.GetAll(name, withMembers, withActiveMembers);

            return(parties.Select(ModelTransformer.PartyToPartyViewModel));
        }