コード例 #1
0
        public Group_Election_AboutViewModel(Election election)
        {
            if (election != null)
            {
                switch ((ElectionStage)election.Stage)
                {
                case ElectionStage.Agitation:
                    StageClass = "agitation-stage";
                    break;

                case ElectionStage.Voting:
                    StageClass = "voting-stage";
                    break;

                case ElectionStage.Completed:
                    StageClass = "completed-stage";
                    break;

                case ElectionStage.Failed:
                    StageClass = "failed-stage";
                    break;
                }

                GroupModersCountString = DeclinationService.OfNumber(election.Group.ModeratorsCount, "модератора", "модераторов", "модераторов");
                ElectionPeriodString   = DeclinationService.OfNumber(election.Group.ElectionFrequency, "месяц", "месяца", "месяцов");
            }
        }
コード例 #2
0
        public _PetitionViewModel(Petition petition, Guid?userId)
        {
            if (petition != null)
            {
                Id         = petition.Id;
                Title      = petition.Title;
                Text       = petition.Text;
                IsFinished = petition.IsFinished;
                IsPrivate  = petition.IsPrivate;
                StartDate  = petition.PublishDate;
                State      = (ContentState)petition.State;

                GroupId = petition.GroupId;

                Coauthors    = petition.Coauthors.Where(c => c.IsAccepted.HasValue && c.IsAccepted.Value).Select(c => new _Petition_CoauthorViewModel(c)).ToList();
                SignersCount = DeclinationService.OfNumber(petition.Signers.Count, "человек", "человека", "человек");

                if (userId.HasValue)
                {
                    IsUserSigned = petition.Signers.Count(x => x.Id == userId.Value) != 0;
                }

                if (petition.PublishDate.HasValue && petition.Duration.HasValue)
                {
                    EndDate = petition.PublishDate.Value.AddDays(petition.Duration.Value);
                }

                if (petition.IsPrivate && petition.GroupId.HasValue)
                {
                    Privacy = "только для членов группы";
                }
            }
        }
コード例 #3
0
 public GroupSurveyOptionViewModel(Option option)
 {
     if (option != null)
     {
         Id               = option.Id;
         Title            = option.Title;
         Description      = option.Description;
         VotesCount       = option.SurveyBulletins.Count;
         VotesCountString = DeclinationService.OfNumber(VotesCount, "голос", "голоса", "голосов");
         Position         = option.Position;
     }
 }
コード例 #4
0
        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));
                    }
                }
            }
        }
コード例 #5
0
        public UserEditViewModel(User user)
        {
            if (user != null)
            {
                Avatar      = ImageService.GetImageUrl <User>(user.Avatar);
                Facebook    = user.Facebook;
                FullName    = user.FullName;
                Name        = user.FirstName;
                Patronymic  = user.Patronymic;
                SurName     = user.SurName;
                Info        = user.Info;
                LiveJournal = user.LiveJournal;
                IsVerified  = user.IsVerified;

                if (user.Address != null)
                {
                    City = user.Address.City.Title;
                }

                BirthDate = user.BirthDate;

                if (user.BirthDate.HasValue)
                {
                    var diff = DateTime.Now.Year - user.BirthDate.Value.Year;
                    Age = DeclinationService.OfNumber((diff + (user.BirthDate.Value <= DateTime.Now.AddYears(-diff) ? 0 : -1)), "год", "года", "лет");
                }

                if (user.BirthAddress != null)
                {
                    switch (user.BirthAddress.City.Type)
                    {
                    case (byte)CityType.City:
                        BirthCity = "г. ";
                        break;

                    case (byte)CityType.Settlement:
                        BirthCity = "п. ";
                        break;

                    case (byte)CityType.Village:
                        BirthCity = "с. ";
                        break;
                    }

                    BirthCity += user.BirthAddress.City.Title;
                }
            }
        }
コード例 #6
0
        public UserProfileViewModel(User user)
        {
            if (user == null)
            {
                return;
            }

            FullName      = user.FullName;
            UserId        = user.Id;
            Info          = TextHelper.CleanTags(user.Info);
            CommentsCount = user.Comments.Count(x => !x.IsHidden);

            IsTicketVerified = user.IsTicketVerified;

            if (user.BirthAddress != null)
            {
                switch (user.BirthAddress.City.Type)
                {
                case (byte)CityType.City:
                    BirthCity = "г. ";
                    break;

                case (byte)CityType.Settlement:
                    BirthCity = "п. ";
                    break;

                case (byte)CityType.Village:
                    BirthCity = "с. ";
                    break;
                }

                BirthCity += user.BirthAddress.City.Title;
            }

            BirthDate = user.BirthDate;
            UTCOffset = new TimeSpan(0, user.UTCOffset, 0);

            if (user.BirthDate.HasValue)
            {
                var diff = DateTime.Now.Year - user.BirthDate.Value.Year;
                Age = DeclinationService.OfNumber((diff + (user.BirthDate.Value <= DateTime.Now.AddYears(-diff) ? 0 : -1)), "год", "года", "лет");
            }

            Contacts    = new User_ContactsViewModel(user);
            DraftsCount = user.Contents.Count(x => x.State == (byte)ContentState.Draft);
            Badges      = new _BadgesViewModel(user);
        }
コード例 #7
0
        public Group_Election_CandidateViewModel(Candidate candidate, GroupMember gm)
        {
            if (candidate != null)
            {
                Id         = candidate.Id;
                UserId     = candidate.GroupMember.UserId;
                Avatar     = ImageService.GetImageUrl <User>(candidate.GroupMember.User.Avatar);
                FullName   = candidate.GroupMember.User.FullName;
                Votes      = DeclinationService.OfNumber(candidate.Electorate.Count, "голос", "голоса", "голосов");
                PetitionId = candidate.Petition == null ? (Guid?)null : candidate.Petition.Id;

                if (gm != null)
                {
                    IsChecked = candidate.Electorate.Count(x => x.OwnerId == gm.Id) > 0;
                }
            }
        }
コード例 #8
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));
                }
            }
        }
コード例 #9
0
        public HomeToday_RecordViewModel(Content content)
        {
            if (content != null)
            {
                Id      = content.Id;
                Url     = content.GetUrl();
                Title   = content.Title;
                Summary = TextHelper.CleanTags(content.Text);
                if (Summary.Length > ConstHelper.MiniSummaryLength)
                {
                    Summary = Summary.Substring(0, ConstHelper.MiniSummaryLength) + "...";
                }
                CommentsCount  = content.Comments.Count(c => !c.IsHidden);
                CommentsString = DeclinationService.OfNumber(CommentsCount, "комментарий", "комментария", "комментариев");
                Date           = content.CreationDate;

                if (content.AuthorId.HasValue)
                {
                    AuthorId      = content.AuthorId.Value;
                    AuthorName    = content.Author.FirstName;
                    AuthorSurname = content.Author.SurName;
                    AuthorAvatar  = ImageService.GetImageUrl <User>(content.Author.Avatar);
                }

                if (content.GroupId.HasValue)
                {
                    GroupId   = content.GroupId.Value;
                    GroupName = content.Group.Name;
                    GroupLogo = ImageService.GetImageUrl <Group>(content.Group.Logo);

                    ContentType = ContentViewType.GroupPost;
                }
                else
                {
                    ContentType = ContentViewType.UserPost;
                }
            }
        }
コード例 #10
0
        public Group_ElectionCandidates_CandidateViewModel(Candidate candidate, int totalMembersCount)
        {
            if (candidate != null)
            {
                Id       = candidate.Id;
                UserId   = candidate.GroupMember.UserId;
                Avatar   = ImageService.GetImageUrl <User>(candidate.GroupMember.User.Avatar);
                FullName = candidate.GroupMember.User.FullName;

                PetitionId = candidate.Petition == null ? (Guid?)null : candidate.Petition.Id;
                if (candidate.Petition != null)
                {
                    var signs = candidate.Petition.Signers.Count;
                    PetitonSigns         = DeclinationService.OfNumber(signs, "подпись", "подписи", "подписей");
                    PetitonRelativeSigns = ((float)signs) / totalMembersCount;
                    PetitonSummary       = TextHelper.CleanTags(candidate.Petition.Text);
                    if (PetitonSummary.Length > 140)
                    {
                        PetitonSummary = PetitonSummary.Substring(0, 140) + "...";
                    }
                }
            }
        }
コード例 #11
0
ファイル: FeedRecord.cs プロジェクト: arbium/democratia2
        public SubscriptionContent(Content content)
        {
            if (content != null)
            {
                AuthorId         = content.AuthorId;
                AuthorFirstName  = content.Author.FirstName;
                AuthorSurname    = content.Author.SurName;
                AuthorPatronymic = content.Author.Patronymic;
                AuthorAvatar     = ImageService.GetImageUrl <User>(content.Author.Avatar, false);
                if (content.Author.Address != null)
                {
                    AuthorCity = content.Author.Address.City.Title;
                }
                CommentsCount      = DeclinationService.OfNumber(content.Comments.Count(c => !c.IsHidden), "комментарий", "комментария", "комментариев");
                Id                 = content.Id;
                IsDiscussionClosed = content.IsDiscussionClosed;
                ContentState       = (ContentState)content.State;

                if (content.State == (byte)ContentState.Premoderated)
                {
                    ContentStateAlert = "ожидает модерации";
                }

                if (content is Post)
                {
                    var post = (content as Post);

                    if (post.GroupId.HasValue)
                    {
                        GroupId         = post.Group.Id;
                        GroupUrl        = post.Group.Url;
                        GroupName       = post.Group.Name;
                        GroupLogo       = ImageService.GetImageUrl <Group>(post.Group.Logo, false);
                        ContentType     = SubscriptionContentType.GroupPost;
                        Url             = content.GetUrl(false);
                        ContentTypeName = "";
                    }
                    else
                    {
                        ContentType     = SubscriptionContentType.UserPost;
                        Url             = content.GetUrl(false);
                        ContentTypeName = "";
                    }
                }
                else if (content is Voting)
                {
                    var voting = (content as Voting);

                    if (voting.GroupId != null)
                    {
                        GroupId   = voting.Group.Id;
                        GroupUrl  = voting.Group.Url;
                        GroupName = voting.Group.Name;
                        GroupLogo = ImageService.GetImageUrl <Group>(voting.Group.Logo, false);

                        if (voting is Petition)
                        {
                            ContentType     = SubscriptionContentType.GroupPetition;
                            Url             = content.GetUrl(false);
                            ContentTypeName = "Петиция";
                        }
                        else if (voting is Poll)
                        {
                            ContentType     = SubscriptionContentType.Poll;
                            Url             = content.GetUrl(false);
                            ContentTypeName = "Голосование";
                        }
                        else if (voting is Survey)
                        {
                            ContentType     = SubscriptionContentType.Survey;
                            Url             = content.GetUrl(false);
                            ContentTypeName = "Опрос";
                        }
                    }
                    else
                    {
                        if (voting is Petition)
                        {
                            ContentType     = SubscriptionContentType.UserPetition;
                            Url             = content.GetUrl(false);
                            ContentTypeName = "Петиция";
                        }
                    }
                }

                if (content.PublishDate.HasValue)
                {
                    PostDate = content.PublishDate.Value;
                }
                else
                {
                    PostDate = content.CreationDate;
                }

                Summary = TextHelper.CleanTags(content.Text);
                if (Summary.Length > ConstHelper.SummaryLength)
                {
                    Summary = Summary.Substring(0, ConstHelper.SummaryLength) + "...";
                }

                Title = content.Title;
            }
        }
コード例 #12
0
        public Group_SurveyViewModel(Survey survey, Guid?userId)
        {
            if (survey != null)
            {
                Id              = survey.Id;
                Title           = survey.Title;
                Text            = survey.Text;
                IsPrivate       = survey.IsPrivate;
                IsFinished      = survey.IsFinished;
                State           = (ContentState)survey.State;
                HasOpenProtocol = survey.HasOpenProtocol;

                GroupId = survey.GroupId;

                Options = survey.Options.Select(x => new GroupSurveyOptionViewModel(x)).OrderBy(x => x.Position).ToList();
                if (survey.PublishDate.HasValue)
                {
                    StartDate = survey.PublishDate.Value;
                    if (survey.Duration.HasValue)
                    {
                        EndDate = survey.PublishDate.Value.AddDays(survey.Duration.Value);
                        if (!survey.IsFinished)
                        {
                            var ts = EndDate.Value - DateTime.Now;
                            TimeRemaining = string.Format("{0} дней {1:00}:{2:00}:{3:00}", (int)ts.TotalDays, ts.Hours, ts.Minutes, ts.Seconds);
                        }
                    }
                }

                var bulletins   = survey.Bulletins;
                var voted       = bulletins.Count(x => x.Result.Count != 0);
                var votedString = DeclinationService.OfNumber(voted, "человек", "человека", "человек");
                if (votedString[votedString.Length - 1] == 'а')
                {
                    VotedUsers = "Проголосовали ";
                }
                else
                {
                    VotedUsers = "Проголосовало ";
                }
                VotedUsers += votedString;
                var abstained       = bulletins.Count - voted;
                var abstainedString = DeclinationService.OfNumber(abstained, "человек", "человека", "человек");
                if (abstainedString[abstainedString.Length - 1] == 'а')
                {
                    AbstainedUsers = "Воздержались ";
                }
                else
                {
                    AbstainedUsers = "Воздержалось ";
                }
                AbstainedUsers += abstainedString;

                VotesCount = 0;
                foreach (var bulletin in bulletins)
                {
                    VotesCount += bulletin.Result.Count;
                }
                VariantsCount       = survey.VariantsCount;
                VariantsCountString = "Вы можете выбрать " + DeclinationService.OfNumber(VariantsCount, "вариант", "варианта", "вариантов");

                if (userId.HasValue)
                {
                    var blt = survey.Bulletins.SingleOrDefault(x => x.UserId == userId);
                    if (blt != null)
                    {
                        IsUserVoted    = true;
                        UserBulletinId = blt.Id;
                        foreach (var o in blt.Result)
                        {
                            Options.Single(x => x.Id == o.Id).IsChecked = true;
                        }
                    }
                }
            }
        }
コード例 #13
0
        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 = "";
                        }
                    }
                }
            }
        }
コード例 #14
0
        public _PetitionStatus_PetitionViewModel(Petition record, Guid?userId)
        {
            if (record != null)
            {
                GroupId = record.GroupId;
                if (GroupId.HasValue)
                {
                    GroupName = record.Group.Name;
                    GroupUrl  = record.Group.Url;

                    Url = record.GetUrl();
                }

                if (record.AuthorId.HasValue)
                {
                    AuthorId         = record.AuthorId.Value;
                    AuthorName       = record.Author.FirstName;
                    AuthorPatronymic = record.Author.Patronymic;
                    AuthorSurname    = record.Author.SurName;
                    AuthorAvatar     = ImageService.GetImageUrl <User>(record.Author.Avatar);

                    if (!GroupId.HasValue)
                    {
                        Url = record.GetUrl();
                    }
                }

                CommentsCount = DeclinationService.OfNumber(record.Comments.Count, "комментарий", "комментария", "комментариев");

                Id    = record.Id;
                Title = record.Title;

                SignaturesCount = record.Signers.Count;
                IsFinished      = record.IsFinished;
                if (record.Duration.HasValue && record.PublishDate.HasValue)
                {
                    FinishDate = record.PublishDate.Value.AddDays(record.Duration.Value);
                }

                IsUserParticipant = false;

                if (userId.HasValue && userId != Guid.Empty)
                {
                    if (record.GroupId.HasValue)
                    {
                        var member = GroupService.UserInGroup(userId.Value, record.GroupId.Value);
                        if (member != null)
                        {
                            IsUserParticipant = true;
                            var signature = record.Signers.Count(x => x.Id == userId);
                            UserSigned = (signature > 0);
                        }
                    }
                    else
                    {
                        IsUserParticipant = true;
                        var signature = record.Signers.Count(x => x.Id == userId);
                        UserSigned = (signature > 0);
                    }
                }
            }
        }