예제 #1
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));
            }
        }
예제 #2
0
        public _ContentLayoutViewModel(Content content, Guid? userId, bool? invert = null)
        {
            if (content != null)
            {
                Id = content.Id;
                Title = content.Title;
                PublishDate = content.PublishDate;
                IsDiscussionClosed = content.IsDiscussionClosed;
                State = (ContentState)content.State;
                Tags = content.Tags.Select(x => new TagViewModel(x)).ToList();
                Likes = new _LikesViewModel(content, userId);
                Comments = new _CommentsBlockViewModel(content, invert);

                if (content is Post)
                {
                    Type = ContentType.Post;
                    Body = new _PostViewModel(content as Post);
                    TypeName = "Пост";
                }
                else if (content is Petition)
                {
                    Type = ContentType.Petition;
                    Body = new _PetitionViewModel(content as Petition, userId);
                    TypeName = "Петиция";
                }
                else if (content is Poll)
                {
                    Type = ContentType.Poll;
                    Body = new Group_PollViewModel(content as Poll);
                    TypeName = "Голосование";
                }
                else if (content is Election)
                {
                    Type = ContentType.Election;
                    Body = new Group_ElectionViewModel(content as Election, userId);
                    TypeName = "Выборы";
                }
                else if (content is Survey)
                {
                    Type = ContentType.Survey;
                    Body = new Group_SurveyViewModel(content as Survey, userId);
                    TypeName = "Опрос";
                }

                if (content.GroupId.HasValue)
                {
                    GroupId = content.GroupId.Value;
                    GroupUrl = content.Group.Url;
                    IsAttached = content.IsGroupAttached(content.GroupId.Value);

                    if (UserContext.Current != null)
                    {
                        IsGroupMember = UserContext.Current.IsUserInGroup(GroupId.Value);
                        IsApprovedMember = UserContext.Current.IsUserApprovedInGroup(GroupId.Value);
                        IsModerator = UserContext.Current.IsUserModeratorInGroup(GroupId.Value);
                        IsContentModerated = content.Group.PrivacyEnum.HasFlag(GroupPrivacy.ContentModeration);

                        if (content.AuthorId.HasValue && UserContext.Current.IsUserApprovedInGroup(GroupId.Value))
                        {
                            var groupMemberAuthor = GroupService.UserInGroup(content.AuthorId.Value, content.Group);

                            Expert expert = null;
                            if (groupMemberAuthor != null)
                                expert = groupMemberAuthor.Expert;

                            var groupMember = GroupService.UserInGroup(UserContext.Current.Id, content.Group);

                            if (expert != null)
                            {
                                var contentTags = content.Tags.Where(x => x.TopicState == (byte)TopicState.GroupTopic);
                                var expertTags = expert.Tags.Intersect(contentTags); // Тэги поста, по которым автор эксперт
                                var delegatedTags = groupMember.ExpertVotes.Select(x => x.Tag);
                                var opportunityDelegateTags = expertTags.ToList().Except(delegatedTags);

                                if (opportunityDelegateTags.Any())
                                    IsDelegateButtonEnabled = true;
                            }
                        }
                    }
                }

                if (content.AuthorId.HasValue)
                {
                    AuthorId = content.AuthorId;
                    AuthorName = content.Author.FullName;
                    AuthorAvatar = ImageService.GetImageUrl<User>(content.Author.Avatar);

                    if (userId.HasValue)
                    {
                        IsAuthor = userId == content.AuthorId;
                        IsPMAllow = content.Author.BlackList.Count(x => x.Id == userId.Value) != 0;
                    }
                }
            }
        }