public Group_ElectionVotingViewModel(Election election, Guid?userId)
        {
            CurrentUserTakingPart = false;
            CurrentUserVoted      = false;

            if (election != null)
            {
                if (!election.PublishDate.HasValue)
                {
                    throw new BusinessLogicException("Данные выборы еще не опубликованы");
                }

                Id = election.Id;

                AgitationStart = election.PublishDate.Value;
                AgitationEnds  = AgitationStart.AddDays(election.AgitationDuration);
                if (election.EndDate.HasValue)
                {
                    ElectionsEnds = election.EndDate.Value;
                }
                var ts = ElectionsEnds - DateTime.Now;
                TimeRemaining         = string.Format("{0} дней {1:00}:{2:00}:{3:00}", (int)ts.TotalDays, ts.Hours, ts.Minutes, ts.Seconds);
                RelativeTimeRemaining = (election.AgitationDuration - (int)ts.TotalDays) * 100 / election.AgitationDuration;

                ElectionFrequency = DeclinationService.OfNumber(election.Group.ElectionFrequency, "месяц", "месяца", "месяцев");
                ModeratorsCount   = DeclinationService.OfNumber(election.Group.ModeratorsCount, "человек", "человека", "человек");
                SignsMinimumLimit = DeclinationService.OfNumber(ConstHelper.CandidatePetitionNecessarySigners, "подпись", "подписи", "подписей");

                var membersCount = DataService.PerThread.GroupMemberSet.Count(x => x.GroupId == election.GroupId && (x.State == (byte)GroupMemberState.Approved || x.State == (byte)GroupMemberState.Moderator));

                var bulletin = DataService.PerThread.BulletinSet.OfType <ElectionBulletin>().SingleOrDefault(x => x.ElectionId == election.Id && x.Owner.UserId == userId);
                if (bulletin != null)
                {
                    CurrentUserTakingPart = true;
                    CurrentUserVoted      = bulletin.Result.Count > 0;
                }

                foreach (var candidate in election.Candidates)
                {
                    if (candidate.Status == (short)CandidateStatus.Confirmed)
                    {
                        var voted = bulletin != null &&
                                    bulletin.Result.SingleOrDefault(x => x.Id == candidate.Id) != null;

                        Candidates.Add(new Group_ElectionVoting_CandidateViewModel(candidate, membersCount, voted));
                    }
                }
            }
        }
Beispiel #2
0
        public Group_ElectionCandidatesViewModel(Election election, Guid?userId)
        {
            if (election != null)
            {
                Id = election.Id;

                if (election.Group != null)
                {
                    GroupId = election.Group.Id;
                }

                if (!election.PublishDate.HasValue)
                {
                    throw new BusinessLogicException("Данные выборы еще не опубликованы");
                }

                if (userId.HasValue && election.GroupId.HasValue)
                {
                    var gm = GroupService.UserInGroup(userId.Value, election.GroupId.Value);
                    if (gm.Candidate != null && gm.Candidate.ElectionId == election.Id)
                    {
                        IsCandidate = true;
                    }
                }

                AgitationStart = election.PublishDate.Value;
                AgitationEnds  = AgitationStart.AddDays(election.AgitationDuration);
                var ts = AgitationEnds - DateTime.Now;
                AgitationTimeRemaining = string.Format("{0} дней {1:00}:{2:00}:{3:00}", (int)ts.TotalDays, ts.Hours, ts.Minutes, ts.Seconds);
                RelativeTimeRemaining  = (election.AgitationDuration - (int)ts.TotalDays) * 100 / election.AgitationDuration;
                ElectionEnd            = election.EndDate.Value;
                ElectionId             = election.Id;
                ElectionFrequency      = DeclinationService.OfNumber(election.Group.ElectionFrequency, "месяц", "месяца", "месяцев");
                ModeratorsCount        = DeclinationService.OfNumber(election.Group.ModeratorsCount, "человек", "человека", "человек");
                SignsMinimumLimit      = DeclinationService.OfNumber(ConstHelper.CandidatePetitionNecessarySigners, "подпись", "подписи", "подписей");

                var membersCount = DataService.PerThread.GroupMemberSet.Count(x => x.GroupId == election.GroupId && (x.State == (byte)GroupMemberState.Approved || x.State == (byte)GroupMemberState.Moderator));
                foreach (var candidate in election.Candidates)
                {
                    Candidates.Add(new Group_ElectionCandidates_CandidateViewModel(candidate, membersCount));
                }
            }
        }