public GroupEditPollViewModel(Poll poll) { var group = poll.Group; if (group != null) { GroupId = group.Id; GroupName = group.Name; GroupUrl = group.Url; IsContentModeration = group.PrivacyEnum.HasFlag(GroupPrivacy.ContentModeration); Topics = group.Tags.Where(t => t.TopicState == (byte)TopicState.GroupTopic).Select(x => new TagViewModel(x)).ToList(); TagTitles = TagsHelper.ConvertTagListToString(poll.Tags.Where(t => t.TopicState != (byte)TopicState.GroupTopic).ToList()); } foreach (var tag in poll.Tags) { if (tag.TopicState == (byte)TopicState.GroupTopic) { var tagVm = Topics.SingleOrDefault(x => x.Id == tag.Id); if (tagVm != null) tagVm.IsChecked = true; } } PollId = poll.Id; Title = poll.Title; Text = poll.Text; IsDraft = poll.State == (byte)ContentState.Draft; if (poll.Duration.HasValue) Duration = poll.Duration.Value; }
public Group_PollViewModel(Poll poll) { Experts = new List<Group_Poll_ExpertViewModel>(); if (poll != null) { Id = poll.Id; Title = poll.Title; Text = poll.Text; IsFinished = poll.IsFinished; State = (ContentState)poll.State; if(poll.GroupId.HasValue) GroupId = poll.GroupId.Value; var publishData = VotingService.GetPollPublishData(poll.Id); if (publishData != null) { IsCreationInProccess = true; IsCreationFailed = publishData.IsFailed; } PollStatus = new Group_PollStatusViewModel(poll); var totalBulletins = poll.Bulletins.Count; foreach (var expertBulletin in poll.Bulletins.Where(x => x.Weight > 1).OrderByDescending(x => x.Weight).Take(5)) Experts.Add(new Group_Poll_ExpertViewModel(expertBulletin, totalBulletins)); } }
public GroupOpenPollReportViewModel(Poll poll) { if (poll == null) return; if (poll.GroupId.HasValue) GroupId = poll.GroupId.Value; Bulletins = poll.Bulletins.Select(x => new GroupOpenPollReport_BulletinViewModel(x)).OrderByDescending(x => x.Result).ThenBy(x => x.Name).ToList(); }
public GroupPollReportViewModel(Poll poll) { if (poll == null) return; if (!poll.IsFinished) throw new BusinessLogicException("Голосование еще не завершено!"); if (poll.GroupId.HasValue) GroupId = poll.GroupId.Value; Bulletins = poll.Bulletins.Select(x => new GroupPollReport_BulletinViewModel(x)).OrderByDescending(x => x.Weight).ThenByDescending(x => x.Result).ThenBy(x => x.Id).ToList(); }
public Group_PollStatusViewModel(Poll poll) { if(UserContext.Current != null) { var userId = UserContext.Current.Id; var gm = DataService.PerThread.GroupMemberSet.FirstOrDefault( x => x.UserId == userId && x.GroupId == poll.GroupId); if (gm != null) { var bulletin = DataService.PerThread.BulletinSet.OfType<PollBulletin>().FirstOrDefault( x => x.OwnerId == gm.Id && x.PollId == poll.Id); if (bulletin != null) PollBulletinId = bulletin.Id.ToString(); } } ReportsUrl = "\\MediaContent\\Reports\\" + poll.Id + ".csv"; if (poll != null) { PollId = poll.Id; ParticipantsCount = poll.Bulletins.Count; HasOpenProtocol = poll.HasOpenProtocol; if (poll.PublishDate.HasValue) { StartDate = poll.PublishDate.Value; FinishDate = poll.PublishDate.Value.AddDays(poll.Duration.Value); IsFinished = poll.IsFinished; if (IsFinished) { switch ((VoteOption)poll.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>голосование не состоялось</span></span>"; break; } } else { var ts = FinishDate - DateTime.Now; TimeRemaing = string.Format("{0} дней {1:00}:{2:00}:{3:00}", (int)ts.TotalDays, ts.Hours, ts.Minutes, ts.Seconds); SecondsLeft = (int)ts.TotalSeconds; } } if (ParticipantsCount > 0) { foreach (var result in poll.Bulletins) { if (result.Result != (byte)VoteOption.NotVoted) { if (result.Result == (byte)VoteOption.Yes) PositiveVotes += result.Weight; if (result.Result == (byte)VoteOption.No) NegativeVotes += result.Weight; if (result.Result == (byte)VoteOption.Refrained) ForefitVotes += result.Weight; TookPart += result.Weight; } } NotVoted = ParticipantsCount - TookPart; double temp = 0; temp = PositiveVotes; RelativePositiveVotes = (int)Math.Round(100 * temp / ParticipantsCount,0, MidpointRounding.ToEven); temp = NegativeVotes; RelativeNegativeVotes = (int)Math.Round(100 * temp / ParticipantsCount, 0, MidpointRounding.ToEven); temp = ForefitVotes; RelativeForefitVotes = (int)Math.Round(100 * temp / ParticipantsCount, 0, MidpointRounding.ToEven); temp = NotVoted; RelativeNotVoted = (int)Math.Round(100 * temp / ParticipantsCount, 0, MidpointRounding.ToEven); poll.Bulletins.OrderByDescending(x => x.Weight).Take(5); } } }
public _PollStatus_VotingViewModel(Poll record, Guid? userId) { if (record != null) { if (record.GroupId.HasValue) GroupId = record.GroupId.Value; GroupName = record.Group.Name; GroupLogo = ImageService.GetImageUrl<Group>(record.Group.Logo); GroupUrl = record.Group.Url; CommentsCount = DeclinationService.OfNumber(record.Comments.Count, "комментарий", "комментария", "комментариев"); Id = record.Id; Title = record.Title; IsFinished = record.IsFinished; VoteResultType = (VoteOption)record.Result; switch (VoteResultType) { 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; } Participants = record.Bulletins.Count; foreach (var vote in record.Bulletins) { if (vote.Result == (byte)VoteOption.Yes) { VotedYes += 1; Voted += 1; } else if (vote.Result == (byte)VoteOption.No) { VotedNo += 1; Voted += 1; } else if (vote.Result == (byte)VoteOption.Refrained) { VotedForefit += 1; Voted += 1; } else if (vote.Result == (byte)VoteOption.NotVoted) { NotVoted += 1; } } if (record.PublishDate.HasValue) { StartDate = record.PublishDate.Value; if (record.Duration.HasValue) FinishDate = record.PublishDate.Value.AddDays(record.Duration.Value); } if (record.Duration.HasValue) Duration = record.Duration.Value; var left = FinishDate - DateTime.Now; if (left.TotalMilliseconds >= 0) TimeLeft = string.Format("{0} {1:00}:{2:00}", DeclinationService.OfNumber((int) left.TotalDays, "день", "дня", "дней"), left.Hours, left.Minutes); IsUserParticipant = false; if (userId.HasValue && userId != Guid.Empty && record.GroupId.HasValue) { var member = GroupService.UserInGroup(userId.Value, record.GroupId.Value); if (member != null) { IsUserParticipant = true; var bulletin = record.Bulletins.SingleOrDefault(x => x.OwnerId == member.Id); if (bulletin != null) { switch ((VoteOption)bulletin.Result) { case VoteOption.Yes: UserVoteResult = "Вы проголосовали <span class='vote yes'>За</span>"; break; case VoteOption.No: UserVoteResult = "Вы проголосовали <span class='vote no'>Против</span>"; break; case VoteOption.Refrained: UserVoteResult = "Вы <span class='vote forefit'>Воздержались</span>"; break; case VoteOption.NotVoted: UserVoteResult = "Вы <span class='vote not'>не голосовали</span> по этому вопросу"; break; } } else UserVoteResult = ""; } } } }
public Poll CreatePoll(string groupUrl, Guid authorId, PollContainer pollData) { var group = GroupService.GetGroupByLabelOrId(groupUrl); var author = GroupService.UserInGroup(authorId, group.Id); if (group.State == (byte)GroupState.Blank) throw new BusinessLogicException("Нельзя создавать голосования в еще не оформленных группах"); if (author == null) throw new BusinessLogicException("Вы не являетесь участником указанной группы"); if (author.State == (byte)GroupMemberState.NotApproved) throw new BusinessLogicException("Вы еще не являетесь участником указанной группы"); var poll = new Poll { GroupId = group.Id, Author = author.User, CreationDate = DateTime.Now, Title = pollData.Title, Text = pollData.Text, State = (byte)(pollData.IsDraft ? ContentState.Draft : ContentState.Premoderated), Duration = pollData.Duration, HasOpenProtocol = pollData.HasOpenProtocol }; if (poll.State == (byte)ContentState.Premoderated) poll.PublishDate = DateTime.Now; foreach (var tag in pollData.Tags) if (group.Tags.Contains(tag)) poll.Tags.Add(tag); DataService.PerThread.SaveChanges(); return poll; }
private void FixupPoll(Poll previousValue) { if (previousValue != null && previousValue.Bulletins.Contains(this)) { previousValue.Bulletins.Remove(this); } if (Poll != null) { if (!Poll.Bulletins.Contains(this)) { Poll.Bulletins.Add(this); } if (PollId != Poll.Id) { PollId = Poll.Id; } } }