예제 #1
0
        public UserMessageViewModel(Message message)
        {
            if (message == null)
            {
                return;
            }

            Id      = message.Id;
            IsInbox = UserContext.Current.Id != message.AuthorId;

            if (message.AuthorId.HasValue)
            {
                AuthorId       = message.AuthorId;
                AuthorFullName = ((User)message.Author).FullName;
            }

            RecipientId       = message.RecipientId;
            RecipientFullName = ((User)message.Recipient).FullName;

            Text    = message.Text.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
            Summary = TextHelper.CleanTags(message.Text);
            if (Summary.Length > ConstHelper.MessageSummaryLength)
            {
                Summary = Summary.Substring(0, ConstHelper.MessageSummaryLength) + "…";
            }

            Html   = message.Text;
            Date   = message.Date;
            IsRead = message.IsRead;
            Type   = message.Type;
        }
        public UserDrafts_PetitionViewModel(Petition petition)
        {
            if (petition != null)
            {
                Id       = petition.Id;
                AuthorId = petition.AuthorId;
                GroupId  = petition.GroupId;

                if (petition.GroupId.HasValue)
                {
                    GroupName = petition.Group.Name;
                    GroupUrl  = petition.Group.Url;

                    if (petition.IsPrivate)
                    {
                        Privacy = "только для членов группы";
                    }
                }

                Controller   = petition.Controller;
                CreationDate = petition.CreationDate;
                Title        = petition.Title;
                Tags         = petition.Tags.Select(x => new TagViewModel(x)).ToList();

                Summary = TextHelper.CleanTags(petition.Text);
                if (Summary.Length > ConstHelper.MiniSummaryLength)
                {
                    Summary = Summary.Substring(0, ConstHelper.MiniSummaryLength) + "…";
                }
            }
        }
예제 #3
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);
        }
예제 #4
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;
                }
            }
        }
예제 #5
0
        public UserDialogs_DialogViewModel(Message message)
        {
            if (message == null)
            {
                return;
            }

            if (message.AuthorId.HasValue)
            {
                var contact = UserContext.Current.Id != message.AuthorId ? (User)message.Author : (User)message.Recipient;
                ContactId     = contact.Id;
                ContactName   = contact.FirstName + " " + contact.SurName;
                ContactAvatar = ImageService.GetImageUrl <User>(contact.Avatar);
            }

            var text = TextHelper.CleanTags(message.Text);

            MessageSummary = text.Length > ConstHelper.MessageSummaryLength ? text.Substring(0, ConstHelper.MessageSummaryLength) + "…" : text;

            DateTime = message.Date;
            IsInbox  = UserContext.Current.Id != message.AuthorId;
            IsRead   = message.IsRead;
        }
예제 #6
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) + "...";
                    }
                }
            }
        }
예제 #7
0
        public HomeGroupsHub_ItemViewModel(Group group, int totalGroups)
        {
            Id      = group.Id;
            Logo    = ImageService.GetImageUrl <Group>(group.Logo);
            Name    = group.Name;
            Url     = group.Url;
            Summary = TextHelper.CleanTags(group.Summary);
            if (Summary.Length > ConstHelper.MiniSummaryLength)
            {
                Summary = Summary.Substring(0, ConstHelper.MiniSummaryLength) + "...";
            }

            RatingPosition = group.GroupRating.OverallRating;
            OldPosition    = group.GroupRating.OldOverallRating;

            MembersRating = (byte)(5 * (float)(totalGroups - group.GroupRating.MembersRating + 1) / totalGroups);
            ExpertsRating = (byte)(5 * (float)(totalGroups - group.GroupRating.ExpertsRating + 1) / totalGroups);
            ContentRating = (byte)(5 * (float)(totalGroups - group.GroupRating.ContentRating + 1) / totalGroups);

            if (group.GroupAd != null)
            {
                AdText = group.GroupAd.Text;
            }
        }
예제 #8
0
        public UserDrafts_ContentViewModel(Content content)
        {
            if (content != null)
            {
                Id         = content.Id;
                Title      = content.Title;
                Summary    = content.Text.Substring(0, Math.Min(ConstHelper.SummaryLength, content.Text.Length));
                AuthorId   = content.AuthorId;
                PostDate   = content.CreationDate;
                Controller = content.Controller;

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

                Tags = new List <TagViewModel>();
                foreach (var tag in content.Tags)
                {
                    Tags.Add(new TagViewModel(tag));
                }
            }
        }
예제 #9
0
        public _ContentFeed_ContentViewModel(Content record)
        {
            if (record != null)
            {
                if (record.GroupId.HasValue)
                {
                    GroupId      = record.Group.Id;
                    GroupUrl     = record.Group.Url;
                    GroupName    = record.Group.Name;
                    GroupLogo    = ImageService.GetImageUrl <Group>(record.Group.Logo);
                    ContentClass = "group";
                }
                else
                {
                    ContentClass = "user";
                }

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

                    if (record.Author.Address != null)
                    {
                        AuthorCity = record.Author.Address.City.Title;
                    }
                }

                /* убрали надпись, теперь числа достаточно
                 * CommentsCount = DeclinationService.OfNumber(record.Comments.Count(c => !c.IsHidden), "комментарий", "комментария", "комментариев");*/
                CommentsCountNum = record.Comments.Count(c => !c.IsHidden);
                Id = record.Id;
                IsDiscussionClosed = record.IsDiscussionClosed;
                if (GroupId.HasValue)
                {
                    IsGroupAttached = record.IsGroupAttached(GroupId.Value);
                }
                if (AuthorId.HasValue)
                {
                    IsUserAttached = record.IsUserAttached(AuthorId.Value);
                }
                ContentState = (ContentState)record.State;
                if (record.State == (byte)ContentState.Premoderated)
                {
                    ContentStateAlert = "ожидает модерации";
                }
                Url = record.GetUrl();

                if (record is Post)
                {
                    ContentClass += " post";
                    ContentType   = record.GroupId.HasValue ? ContentViewType.GroupPost : ContentViewType.UserPost;
                }
                else if (record is Voting)
                {
                    IsFinished = (record as Voting).IsFinished;

                    if (record.PublishDate.HasValue)
                    {
                        var duration = (record as Voting).Duration;

                        StartDate = record.PublishDate.Value;
                        if (duration.HasValue)
                        {
                            EndDate = record.PublishDate.Value.AddDays(duration.Value);
                        }
                    }

                    if (record is Petition)
                    {
                        ContentClass   += " petition";
                        ContentType     = record.GroupId.HasValue ? ContentViewType.GroupPetition : ContentViewType.UserPetition;
                        ContentTypeName = "Петиция";
                    }
                    else if (record is Poll)
                    {
                        ContentClass   += " poll";
                        ContentType     = ContentViewType.Poll;
                        ContentTypeName = "Голосование";

                        var poll = record as Poll;
                        if (poll.PublishDate.HasValue)
                        {
                            if (UserContext.Current != null)
                            {
                                var blt = DataService.PerThread.BulletinSet.OfType <PollBulletin>()
                                          .SingleOrDefault(x => x.Owner.UserId == UserContext.Current.Id && x.PollId == poll.Id);
                                if (blt != null)
                                {
                                    Vote = (VoteOption)blt.Result;
                                }

                                if (poll.IsFinished)
                                {
                                    Result = (VoteOption)poll.Result;
                                }
                            }
                        }
                    }
                    else if (record is Election)
                    {
                        ContentClass   += " election";
                        ContentType     = ContentViewType.Election;
                        ContentTypeName = "Выборы";
                    }
                    else if (record is Survey)
                    {
                        ContentClass   += " survey";
                        ContentType     = ContentViewType.Survey;
                        ContentTypeName = "Опрос";
                    }
                }

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

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

                Title = record.Title;

                Tags = new List <TagViewModel>();
                foreach (var tag in record.Tags.Take(10))
                {
                    Tags.Add(new TagViewModel(tag));
                }
            }
        }
예제 #10
0
        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;
            }
        }
예제 #11
0
        public SearchTag_ContentViewModel(Content content)
        {
            if (content != null)
            {
                if (content.AuthorId.HasValue)
                {
                    AuthorName   = content.Author.FullName;
                    AuthorId     = content.AuthorId;
                    AuthorAvatar = ImageService.GetImageUrl <User>(content.Author.Avatar);
                }

                if (content.GroupId.HasValue)
                {
                    GroupUrl  = content.Group.Url;
                    GroupName = content.Group.Name;
                    GroupLogo = content.Group.Logo;
                }

                ContentState = (ContentState)content.State;

                Url     = content.GetUrl();
                Title   = content.Title;
                Summary = TextHelper.CleanTags(content.Text);
                if (Summary.Length > 200)
                {
                    Summary = Summary.Substring(0, 200) + "...";
                }

                if (content is Post)
                {
                    if (content.GroupId.HasValue)
                    {
                        ContentClass = "group";
                        ContentType  = ContentViewType.GroupPost;
                    }
                    else
                    {
                        ContentClass = "user";
                        ContentType  = ContentViewType.UserPost;
                    }

                    ContentClass += " post";
                }
                else if (content is Petition)
                {
                    if (content.GroupId.HasValue)
                    {
                        ContentClass = "group";
                        ContentType  = ContentViewType.GroupPetition;
                    }
                    else
                    {
                        ContentClass = "user";
                        ContentType  = ContentViewType.UserPetition;
                    }

                    ContentClass += " petition";
                }
                else if (content is Poll)
                {
                    ContentClass = "poll";
                    ContentType  = ContentViewType.Poll;
                }
                else if (content is Election)
                {
                    ContentClass = "election";
                    ContentType  = ContentViewType.Election;
                }
            }
        }
예제 #12
0
        /// <param name="result">Контент/Комментарий/Группа</param>
        public SearchIndex_ResultViewModel(object result)
        {
            if (result != null)
            {
                if (result is Comment)
                {
                    var comment = result as Comment;

                    Type  = "комментарий";
                    Image = ImageService.GetImageUrl <User>(comment.User.Avatar);
                    Title = comment.Content.Title;

                    Text = TextHelper.CleanTags(comment.Text);
                    if (Text.Length > ConstHelper.MiniSummaryLength)
                    {
                        Text = Text.Substring(0, ConstHelper.MiniSummaryLength) + "…";
                    }

                    Url = comment.Content.GetUrl(comment);

                    Tags = comment.Content.Tags.Select(x => new TagViewModel(x)).ToList();
                }
                else if (result is Post)
                {
                    var post = result as Post;

                    Type  = "пост";
                    Title = post.Title;
                    Url   = UrlHelper.GetUrl <Post>(post.Id);

                    Text = TextHelper.CleanTags(post.Text);
                    if (Text.Length > ConstHelper.MiniSummaryLength)
                    {
                        Text = Text.Substring(0, ConstHelper.MiniSummaryLength) + "…";
                    }

                    if (post.GroupId.HasValue)
                    {
                        Image = ImageService.GetImageUrl <Group>(post.Group.Logo);
                    }
                    else if (post.AuthorId.HasValue)
                    {
                        Image = ImageService.GetImageUrl <User>(post.Author.Avatar);
                    }

                    Tags = post.Tags.Select(x => new TagViewModel(x)).ToList();
                }
                else if (result is Voting)
                {
                    var voting = result as Voting;

                    Type  = "голосование";
                    Title = voting.Title;
                    Url   = UrlHelper.GetUrl <Voting>(voting.Id);

                    Text = TextHelper.CleanTags(voting.Text);
                    if (Text.Length > ConstHelper.MiniSummaryLength)
                    {
                        Text = Text.Substring(0, ConstHelper.MiniSummaryLength) + "…";
                    }

                    if (voting.GroupId.HasValue)
                    {
                        Image = ImageService.GetImageUrl <Group>(voting.Group.Logo);
                    }
                    else if (voting.AuthorId.HasValue)
                    {
                        Image = ImageService.GetImageUrl <User>(voting.Author.Avatar);
                    }

                    Tags = voting.Tags.Select(x => new TagViewModel(x)).ToList();
                }
                else if (result is Group)
                {
                    var group = result as Group;

                    Type  = "группа";
                    Title = group.Name;
                    Image = ImageService.GetImageUrl <Group>(group.Logo);
                    Url   = UrlHelper.GetUrl <Group>(group.Url);

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

                    Tags = group.Tags.Where(x => x.TopicState == (byte)TopicState.GroupTopic).Select(x => new TagViewModel(x)).ToList();
                }
            }
        }
예제 #13
0
        public override ICachedViewModel Initialize()
        {
            var group = GroupService.GetGroupByLabelOrId(_groupId);

            var membersCount    = DataService.PerThread.GroupMemberSet.Count(gm => gm.GroupId == group.Id && (gm.State == (byte)GroupMemberState.Approved || gm.State == (byte)GroupMemberState.Moderator));
            var moderatorsCount = DataService.PerThread.GroupMemberSet.Count(gm => gm.GroupId == group.Id && gm.State == (byte)GroupMemberState.Moderator);

            State        = (GroupState)group.State;
            GroupId      = group.Id;
            MembersCount = membersCount;
            Name         = group.Name;
            Summary      = TextHelper.CleanTags(group.Summary);
            if (Summary.Length > 500)
            {
                Summary = Summary.Substring(0, 500) + "…";
            }
            Url                     = group.Url;
            GroupTagsCount          = group.Tags.Count;
            RequiredModers          = group.ModeratorsCount - moderatorsCount;
            IsExpertable            = group.Tags.Count != 0;
            IsEditEnabled           = group.Content.OfType <Election>().Count(x => !x.IsFinished) == 0;
            IsInvisible             = group.PrivacyEnum.HasFlag(GroupPrivacy.Invisible);
            IsCreateElectionEnabled = GroupService.CanElectionsBeStarted(group);

            Topics = group.Tags.Where(x => x.TopicState == (byte)TopicState.GroupTopic).OrderByDescending(x => x.Weight).Take(5).ToList()
                     .Select(x => new GroupIndex_TopicViewModel(x)).ToList();

            IQueryable <Content> feedQueue;

            if (_userId.HasValue && _userId.Value != Guid.Empty)
            {
                var uig = GroupService.UserInGroup(_userId.Value, GroupId);

                if (uig != null)
                {
                    MemberId = uig.Id;

                    feedQueue = DataService.PerThread.ContentSet.Where(x => x.GroupId.HasValue && x.GroupId.Value == _groupId &&
                                                                       (x.State == (byte)ContentState.Approved || (x.State == (byte)ContentState.Premoderated && (x.AuthorId.HasValue && x.AuthorId.Value == _userId.Value || uig.State == (byte)GroupMemberState.Moderator))));
                }
                else
                {
                    feedQueue = DataService.PerThread.ContentSet.Where(x => x.GroupId.HasValue && x.GroupId.Value == _groupId && x.State == (byte)ContentState.Approved);
                }
            }
            else
            {
                feedQueue = DataService.PerThread.ContentSet.Where(x => x.GroupId.HasValue && x.GroupId.Value == _groupId && x.State == (byte)ContentState.Approved);
            }

            if (ByDate.HasValue && ByDate.Value)
            {
                feedQueue = feedQueue.OrderByDescending(x => x.PublishDate ?? DateTime.Now);
            }
            else
            {
                /*feedQueue = (from content in feedQueue.Where(x => x.PublishDate.HasValue)
                 *  join comment in DataService.PerThread.CommentSet on content.Id equals comment.ContentId
                 *  join like in DataService.PerThread.LikeSet on content.Id equals like.ContentId
                 *  let commentsCount = content.Comments.Count
                 *  let likesCount = content.Likes.Count
                 *  let plusesCount = content.Likes.Count(x => x.Value)
                 *  let minusesCount = content.Likes.Count(x => !x.Value)
                 *  //orderby (Math.Pow(plusesCount * likesCount, 0.5) + commentsCount / 10) /
                 *  //    Math.Pow(EntityFunctions.DiffDays(content.PublishDate.Value, DateTime.Now).Value + 0.01, 0.5) /
                 *  //    Math.Pow(minusesCount + 1, 0.5) descending
                 *  orderby (Math.Pow(plusesCount * likesCount, 0.5) + commentsCount / 10 + 7) /
                 *      Math.Pow((EntityFunctions.DiffDays(content.PublishDate.Value, DateTime.Now).Value + 0.01) * (minusesCount + 1), 0.5)
                 *      descending
                 *  select content);*/

                feedQueue = feedQueue.OrderByDescending(x => (Math.Pow(x.Likes.Count(y => y.Value) * x.Likes.Count, 0.5) + x.Comments.Count / 10 + 7) /
                                                        Math.Pow((EntityFunctions.DiffDays(x.PublishDate.Value, DateTime.Now).Value + 0.01) * (x.Likes.Count(y => !y.Value) + 1), 0.5));
            }

            if (TopicId.HasValue)
            {
                feedQueue = feedQueue.Where(x => x.Tags.Count(y => y.Id == TopicId.Value) != 0);
            }

            Feed   = new _ContentFeedViewModel(feedQueue, Url);
            Moders = new Group_ModersViewModel(group);

            return(this);
        }