public GroupOpenPollReport_BulletinViewModel(PollBulletin bulletin)
        {
            if (bulletin == null)
                return;

            Name = bulletin.Owner.User.FullName;
            Result = (VoteOption)bulletin.Result;
        }
        public GroupPollReport_BulletinViewModel(PollBulletin bulletin)
        {
            if (bulletin == null)
                return;

            Id = bulletin.Id;
            Weight = bulletin.Weight;
            Result = (VoteOption)bulletin.Result;
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
0
        private void CreateBulletins(Guid pollId)
        {
            var poll = DataService.PerThread.ContentSet.OfType<Poll>().SingleOrDefault(x => x.Id == pollId);
            var data = new PollPublishDataContainer();

            if (poll == null)
            {
                data.Fail("Указанное голосование не найдено");
                return;
            }

            if (_pollsInPublish.ContainsKey(pollId))
                _pollsInPublish.Remove(pollId);

            _pollsInPublish.Add(pollId, data);

            // Начинаем печатать бюллетени
            try
            {
                var clearlist = DataService.PerThread.BulletinSet.OfType<PollBulletin>().Where(x => x.PollId == pollId).ToList();
                foreach (var bulletin in clearlist)
                    DataService.PerThread.BulletinSet.DeleteObject(bulletin);

                poll.Bulletins.Clear();

                DataService.PerThread.SaveChanges();

                var members = poll.Group.GroupMembers
                    .Where(x => !x.User.IsOutdated && (x.State == (byte) GroupMemberState.Approved || x.State == (byte) GroupMemberState.Moderator))
                    .ToList();

                // создаем пустые бюллетени
                foreach (var member in members)
                {
                    var bulletin = new PollBulletin
                    {
                        OwnerId = member.Id,
                        Weight = 1
                    };
                    poll.Bulletins.Add(bulletin);
                }

                // расставляем делегирование
                foreach (var member in members)
                {
                    var experts = member.ExpertVotes;
                    if (experts.Count > 0)
                    {
                        foreach (var expert in experts)
                        {
                            if (poll.Tags.Contains(expert.Tag))
                            {
                                var grantorBulletin = poll.Bulletins.Single(x => x.OwnerId == member.Id);
                                var expertBulletin = poll.Bulletins.Single(x => x.OwnerId == expert.Expert.GroupMember.Id);

                                if (!grantorBulletin.ExpertBulletins.Contains(expertBulletin))
                                    grantorBulletin.ExpertBulletins.Add(expertBulletin);
                            }
                        }
                    }
                }

                // распределяем вес
                foreach (var bulletin in poll.Bulletins)
                {
                    if (bulletin.GrantorBulletins.Count == 0)
                    {
                        if (bulletin.ExpertBulletins.Count == 1)
                        {
                            bulletin.ExpertBulletins.First().Weight += 1;
                            bulletin.Weight = 0;
                        }

                        // если несколько экспертов, то человек принимает решение сам, а решения экспертов носят рекомендательный характер
                        // но если при подсчете голосов эксперты солидарны и человек не голосовал сам, то считаем как считает большинство экспертов
                    }
                }

                poll.PublishDate = DateTime.Now;
                poll.State = (byte)ContentState.Approved;

                DataService.PerThread.SaveChanges();

                _pollsInPublish.Remove(poll.Id);

                if (poll.Duration.HasValue)
                    ScheduleService.AddJob(new FinishPollTask(poll.Id), poll.PublishDate.Value.AddDays(poll.Duration.Value), false, null, false);

                MessageService.SendToGroup(poll.Group, MessageComposer.ComposePollNotice(poll.Id), MessageType.PollNotice);
            }
            catch (Exception exp)
            {
                if (_pollsInPublish.ContainsKey(poll.Id))
                {
                    var info = _pollsInPublish[poll.Id];
                    info.Fail("Создание бюллетений прервано с ошибкой: " + exp.InnerException);
                }
            }
        }
Exemplo n.º 5
0
        public Group_Poll_ExpertViewModel(PollBulletin bulletin, int totalBulletins)
        {
            if (bulletin != null)
            {
                Id = bulletin.Owner.UserId;
                var expert = bulletin.Owner.User;
                Name = expert.FirstName;
                Surname = expert.SurName;
                Patronymic = expert.Patronymic;
                Avatar = ImageService.GetImageUrl<User>(expert.Avatar);

                Represent = bulletin.Weight;
                double weight = Represent;
                RelativeRepresent = Math.Round((100 * weight / totalBulletins), 2);
                Comment = bulletin.Comment;

                switch ((VoteOption)bulletin.Result)
                {
                    case VoteOption.Yes: VoteResult = "<span class='vote yes'>За</span>"; break;
                    case VoteOption.No: VoteResult = "<span class='vote no'>Против</span>"; break;
                    case VoteOption.Refrained: VoteResult = "<span class='vote forefit'>Воздержался</span>"; break;
                    case VoteOption.NotVoted: VoteResult = "<span class='vote not'>Не голосовал</span>"; break;
                }

            }
        }
        public Group_PollVotePanel_ExpertViewModel(PollBulletin expertBulletin)
        {
            if (expertBulletin != null)
            {
                var expert = expertBulletin.Owner.User;
                Id = expert.Id;
                Name = expert.FirstName;
                SurName = expert.SurName;
                Patronymic = expert.Patronymic;
                Avatar = ImageService.GetImageUrl<User>(expert.Avatar);

                switch ((VoteOption)expertBulletin.Result)
                {
                    case VoteOption.Yes: VoteResult = "<span class='vote yes'>За</span>"; break;
                    case VoteOption.No: VoteResult = "<span class='vote no'>Против</span>"; break;
                    case VoteOption.Refrained: VoteResult = "<span class='vote forefit'>Воздержался</span>"; break;
                    case VoteOption.NotVoted: VoteResult = "<span class='vote not'>Не голосовал</span>"; break;
                }
            }
        }