示例#1
0
        private void _StartElection(Guid electionId)
        {
            var election = DataService.PerThread.ContentSet.OfType<Election>().Single(x => x.Id == electionId);

            try
            {
                election.ElectionBulletins.Clear();
                foreach (var member in election.Group.GroupMembers.Where(x => (x.State == (byte)GroupMemberState.Approved || x.State == (byte)GroupMemberState.Moderator) && !x.User.IsOutdated))
                {
                    var bulletin = new ElectionBulletin
                    {
                        OwnerId = member.Id,
                        ElectionId = electionId
                    };
                    election.ElectionBulletins.Add(bulletin);
                }

                foreach (var candidate in election.Candidates.Where(x => x.Status == (byte)CandidateStatus.Declared))
                {
                    if (candidate.Petition.Signers.Count >= ConstHelper.CandidatePetitionNecessarySigners)
                        candidate.Status = (byte)CandidateStatus.Confirmed;
                }

                if (election.Candidates.Count(x => x.Status == (byte)CandidateStatus.Confirmed) < election.Group.ModeratorsCount)
                {
                    _frozenElections.Remove(electionId);
                    FinishElection(election.Id);
                }
                else
                    election.Stage = (byte)ElectionStage.Voting;

                DataService.PerThread.SaveChanges();
                ScheduleService.AddJob(new FinishElectionTask(election.Id), DateTime.Now.AddDays(election.Duration.Value), false, null, true);
            }
            catch (Exception exp)
            {
                _frozenElections.Remove(electionId);

                throw new BusinessLogicException("Создание бюллетеней прервано с ошибкой: " + exp.InnerException);
            }
        }
示例#2
0
        private void PrintNewBulletins()
        {
            if (!_isPrinting)
            {
                _isPrinting = true;

                while (BulletinRequestQueue.Count != 0)
                {
                    KeyValuePair<Guid, Guid> request;
                    if (BulletinRequestQueue.TryDequeue(out request))
                    {
                        var votingId = request.Key;
                        var userId = request.Value;
                        var voting = DataService.PerThread.ContentSet.OfType<Voting>().SingleOrDefault(x => x.Id == votingId);

                        if (voting != null)
                        {
                            if (voting is Poll)
                            {
                                var poll = voting as Poll;
                                var bulletin = new PollBulletin();

                                if (poll.State == (byte)ContentState.Approved && !poll.IsFinished)
                                {
                                    var groupMember = GroupService.UserInGroup(userId, poll.Group);

                                    if (groupMember != null && (groupMember.State == (byte)GroupMemberState.Approved || groupMember.State == (byte)GroupMemberState.Moderator))
                                    {
                                        if (poll.Bulletins.Count(x => x.OwnerId == groupMember.Id) == 0)
                                        {
                                            bulletin.Owner = groupMember;
                                            bulletin.Weight = 1;
                                            poll.Bulletins.Add(bulletin);
                                            DataService.PerThread.SaveChanges();
                                        }
                                    }
                                }
                            }
                            else if (voting is Election)
                            {
                                var election = voting as Election;
                                var bulletin = new ElectionBulletin();

                                if (election.State == (byte)ContentState.Approved && !election.IsFinished)
                                {
                                    var groupMember = GroupService.UserInGroup(userId, election.Group);

                                    if (groupMember != null && (groupMember.State == (byte)GroupMemberState.Approved || groupMember.State == (byte)GroupMemberState.Moderator))
                                    {
                                        if (election.ElectionBulletins.Count(x => x.OwnerId == groupMember.Id) == 0)
                                        {
                                            bulletin.Owner = groupMember;
                                            election.ElectionBulletins.Add(bulletin);
                                            DataService.PerThread.SaveChanges();
                                        }
                                    }
                                }
                            }
                        }
                    }

                    Thread.Sleep(1);
                }

                _isPrinting = false;
            }
        }