Пример #1
0
 public Group_ElectionViewModel()
 {
     Candidates = new List<Group_Election_CandidateViewModel>();
     Winners = new List<Group_Election_CandidateViewModel>();
     About = new Group_Election_AboutViewModel();
     ElectionCandidates = new Group_ElectionCandidatesViewModel();
     ElectionVoting = new Group_ElectionVotingViewModel();
 }
Пример #2
0
 public Group_ElectionViewModel()
 {
     Candidates         = new List <Group_Election_CandidateViewModel>();
     Winners            = new List <Group_Election_CandidateViewModel>();
     About              = new Group_Election_AboutViewModel();
     ElectionCandidates = new Group_ElectionCandidatesViewModel();
     ElectionVoting     = new Group_ElectionVotingViewModel();
 }
Пример #3
0
        public Group_ElectionViewModel(Election election, Guid? userId)
        {
            if (election != null)
            {
                Id = election.Id;
                Title = election.Title;
                Stage = (ElectionStage)election.Stage;
                Quorum = election.Quorum;
                Turnout = election.Turnout;
                GroupModersCount = election.Group.ModeratorsCount;
                About = new Group_Election_AboutViewModel(election);

                GroupMember gm = null;
                if (userId.HasValue && election.GroupId.HasValue)
                    gm = GroupService.UserInGroup(userId.Value, election.GroupId.Value);

                IEnumerable<Candidate> candidates = election.Candidates.Where(x => x.Petition != null).OrderByDescending(x => x.Petition.Signers.Count);
                candidates = candidates.Union(election.Candidates.Where(x => x.Petition == null));
                if (election.Stage != (byte)ElectionStage.Agitation)
                    candidates = candidates.Where(x => x.Status == (byte)CandidateStatus.Confirmed);
                Candidates = candidates.Select(x => new Group_Election_CandidateViewModel(x, gm)).ToList();
                Winners = election.Candidates
                    .Where(x => x.Status == (byte)CandidateStatus.Winner)
                    .OrderByDescending(x => x.Electorate.Count)
                    .Select(x => new Group_Election_CandidateViewModel(x, gm))
                    .ToList();

                switch (Stage)
                {
                    case ElectionStage.Agitation: ElectionCandidates = new Group_ElectionCandidatesViewModel(election, userId); break;
                    case ElectionStage.Voting: ElectionVoting = new Group_ElectionVotingViewModel(election, userId); break;
                }
            }
            else
            {
                Candidates = new List<Group_Election_CandidateViewModel>();
                Winners = new List<Group_Election_CandidateViewModel>();
                About = new Group_Election_AboutViewModel();
                ElectionCandidates = new Group_ElectionCandidatesViewModel();
                ElectionVoting = new Group_ElectionVotingViewModel();
            }

            if (UserContext.Current != null)
            {
                var candidate = Candidates.FirstOrDefault(x => x.UserId == UserContext.Current.Id);
                if (candidate != null)
                {
                    IsCandidate = true;
                    CandidateId = candidate.Id;
                }
                else
                    CandidateId = null;
            }
        }
Пример #4
0
        public Group_ElectionViewModel(Election election, Guid?userId)
        {
            if (election != null)
            {
                Id               = election.Id;
                Title            = election.Title;
                Stage            = (ElectionStage)election.Stage;
                Quorum           = election.Quorum;
                Turnout          = election.Turnout;
                GroupModersCount = election.Group.ModeratorsCount;
                About            = new Group_Election_AboutViewModel(election);

                GroupMember gm = null;
                if (userId.HasValue && election.GroupId.HasValue)
                {
                    gm = GroupService.UserInGroup(userId.Value, election.GroupId.Value);
                }

                IEnumerable <Candidate> candidates = election.Candidates.Where(x => x.Petition != null).OrderByDescending(x => x.Petition.Signers.Count);
                candidates = candidates.Union(election.Candidates.Where(x => x.Petition == null));
                if (election.Stage != (byte)ElectionStage.Agitation)
                {
                    candidates = candidates.Where(x => x.Status == (byte)CandidateStatus.Confirmed);
                }
                Candidates = candidates.Select(x => new Group_Election_CandidateViewModel(x, gm)).ToList();
                Winners    = election.Candidates
                             .Where(x => x.Status == (byte)CandidateStatus.Winner)
                             .OrderByDescending(x => x.Electorate.Count)
                             .Select(x => new Group_Election_CandidateViewModel(x, gm))
                             .ToList();

                switch (Stage)
                {
                case ElectionStage.Agitation: ElectionCandidates = new Group_ElectionCandidatesViewModel(election, userId); break;

                case ElectionStage.Voting: ElectionVoting = new Group_ElectionVotingViewModel(election, userId); break;
                }
            }
            else
            {
                Candidates         = new List <Group_Election_CandidateViewModel>();
                Winners            = new List <Group_Election_CandidateViewModel>();
                About              = new Group_Election_AboutViewModel();
                ElectionCandidates = new Group_ElectionCandidatesViewModel();
                ElectionVoting     = new Group_ElectionVotingViewModel();
            }

            if (UserContext.Current != null)
            {
                var candidate = Candidates.FirstOrDefault(x => x.UserId == UserContext.Current.Id);
                if (candidate != null)
                {
                    IsCandidate = true;
                    CandidateId = candidate.Id;
                }
                else
                {
                    CandidateId = null;
                }
            }
        }