public _TagContent_ContentViewModel(Content content) { if (content != null) { Id = content.Id; Title = content.Title; Url = content.GetUrl(); } if (content is Post) { ContentType = "Пост"; } else if (content is Poll) { ContentType = "Голосование"; } else if (content is Survey) { ContentType = "Опрос"; } else if (content is Petition) { ContentType = "Петиция"; } else if (content is Election) { ContentType = "Выборы"; } }
public _RssFeedItemViewModel(Content content) { Title = content.Title; Link = content.GetUrl(false); Description = content.Text; PublishDate = content.PublishDate.Value.ToString("dd MMMM yyyy"); ; }
public _CommentsBlockViewModel(Content content, bool? invert = null) { if (content != null) { ContentId = content.Id; IsDiscussionClosed = content.IsDiscussionClosed; if (content.GroupId.HasValue && UserContext.Current != null && !GroupService.IsUserApprovedInGroup(UserContext.Current.Id, content.Group) && content.Group.PrivacyEnum.HasFlag(GroupPrivacy.PrivateDiscussion)) IsDiscussionUnavailable = true; Comments = new _CommentsViewModel(content, invert); } }
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)); } }
public _LikesViewModel(Content content, Guid? userId) { if (content != null) { TargetId = content.Id; TargetType = (byte)WtfLikes.Content; if (content.AuthorId.HasValue) IsAuthor = content.AuthorId.Value == userId; var likes = content.Likes; LikesCount = likes.Count(l => l.Value); DislikesCount = likes.Count(l => l.Value == false); var like = likes.SingleOrDefault(l => l.ContentId == content.Id && l.User.Id == userId); if (like != null) Vote = like.Value; } }
public _CommentsViewModel(Content content, bool? invert = null) { if (content != null) { Invert = invert; ContentId = content.Id; IsFork = false; IsDiscussionClosed = content.IsDiscussionClosed; ContentId = content.Id; var comments = content.Comments.Where(c => !c.ParentCommentId.HasValue); if (invert.HasValue && invert.Value) comments = comments.OrderBy(c => c.DateTime); else comments = comments.OrderByDescending(c => c.DateTime); Comments = comments.ToPaginationList(ConstHelper.CommentsPerPage, x => new _Comments_CommentViewModel(x)); CommentsCount = content.Comments.Count(c => !c.IsHidden); if (CommentsCount > 3) TopComments = content.Comments.Where(x => !x.IsHidden && x.Rating > 0).OrderByDescending(x => x.Rating).ThenByDescending(x => x.DateTime).Take(3).ToList() .Select(x => new _Comments_CommentViewModel(x)).ToList(); } }
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; } }
public void UpdateContentCache(Content content) { if (content.GroupId.HasValue) CachService.DropViewModelByModel(content.GroupId.Value); if (content.AuthorId.HasValue) CachService.DropViewModelByModel(content.AuthorId.Value); }
public void Unpublish(Content content, Guid userId) { if (content == null) throw new BusinessLogicException("Не найден указанный контент"); if (content.State != (byte)ContentState.Approved && content.State != (byte)ContentState.Premoderated) throw new BusinessLogicException("Нельзя отменить публикацию данного контента"); if (content is Poll) throw new BusinessLogicException("Нельзя отменять публикацию голосований"); if (!IsAuthor(content, userId)) throw new BusinessLogicException("Нельзя отменять публикацию чужого контента"); if (content.GroupId.HasValue) // Контент привязан к группе GroupService.UserInGroup(userId, content.GroupId.Value, true); content.State = (byte)ContentState.Draft; UpdateContentCache(content); }
public static void Restore(Content content, Guid userId) { _current.Restore(content, userId); }
public static void Delete(Content content, Guid userId) { _current.Delete(content, userId); }
private void FixupContent(Content previousValue) { if (previousValue != null && previousValue.Comments.Contains(this)) { previousValue.Comments.Remove(this); } if (Content != null) { if (!Content.Comments.Contains(this)) { Content.Comments.Add(this); } if (ContentId != Content.Id) { ContentId = Content.Id; } } }
public bool IsAuthor(Content content, Guid userId) { if (content == null) throw new BusinessLogicException("Невозможно проверить является ли указанный пользователь автором, т.к. не найден указанный контент"); return content.AuthorId == userId; }
public void Delete(Content content, Guid userId) { if (content == null) throw new BusinessLogicException("Не найден указанный контент"); if (content.GroupId.HasValue) GroupService.UserInGroup(userId, content.Group, true); if (!IsAuthor(content, userId)) throw new BusinessLogicException("Удалять контент могут только авторы"); content.State = (byte)ContentState.Deleted; UpdateContentCache(content); }
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; } } } }
private void FixupContent(Content previousValue) { if (previousValue != null && previousValue.Likes.Contains(this)) { previousValue.Likes.Remove(this); } if (Content != null) { if (!Content.Likes.Contains(this)) { Content.Likes.Add(this); } if (ContentId != Content.Id) { ContentId = Content.Id; } } else if (!_settingFK) { ContentId = null; } }
public static void ToggleDiscussion(bool show, Content content, Guid userId) { _current.ToggleDiscussion(show, content, userId); }
public static void ToggleBlock(bool block, Content content, Guid userId) { _current.ToggleBlock(block, content, userId); }
public void Publish(Content content, Guid userId) { if (content == null) throw new BusinessLogicException("Не найден указанный контент"); if (content.State != (byte)ContentState.Draft && content.State != (byte)ContentState.Premoderated) throw new BusinessLogicException("Данный контент нельзя публиковать"); if (content.GroupId.HasValue) // Контент привязан к группе { var member = GroupService.UserInGroup(userId, content.GroupId.Value, true); if (content.Group.PrivacyEnum.HasFlag(GroupPrivacy.ContentModeration)) { if (member.State == (byte)GroupMemberState.Moderator) content.State = (byte)ContentState.Approved; else { if (!IsAuthor(content, userId)) throw new BusinessLogicException("Нельзя публиковать чужой контент"); content.State = (byte)ContentState.Premoderated; } } else { if (content is Post && (content as Post).IsExternal) content.State = member.State == (byte)GroupMemberState.Moderator ? (byte)ContentState.Approved : (byte)ContentState.Premoderated; else content.State = (byte)ContentState.Approved; } } else { if (!IsAuthor(content, userId)) throw new BusinessLogicException("Нельзя публиковать чужой контент"); content.State = (byte)ContentState.Approved; } content.PublishDate = DateTime.Now; if (content.State == (byte)ContentState.Approved) { if (content is Poll) VotingService.StartPoll(content.Id, userId); else if (content is Survey) VotingService.StartSurvey(content.Id); } UpdateContentCache(content); }
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)); } }
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; } }
public static bool IsAuthor(Content content, Guid userId) { return _current.IsAuthor(content, userId); }
public void ToggleBlock(bool block, Content content, Guid userId) { if (content == null) throw new BusinessLogicException("Не найден указанный контент"); var group = content.Group; if (group == null) throw new BusinessLogicException("Можно блокировать только контент, привязанный к группе"); var member = GroupService.UserInGroup(userId, group, true); if (member.State != (byte)GroupMemberState.Moderator) throw new BusinessLogicException("Только модераторы имеют право блокировать контент"); if (block) content.State = (byte)ContentState.Blocked; else if (content.State == (byte)ContentState.Blocked) content.State = (byte)ContentState.Approved; UpdateContentCache(content); }
private void FixupContent(Content previousValue) { if (previousValue != null && ReferenceEquals(previousValue.Attach, this)) { previousValue.Attach = null; } if (Content != null) { Content.Attach = this; } }
public void ToggleDiscussion(bool show, Content content, Guid userId) { if (content == null) throw new BusinessLogicException("Не найден указанный контент"); var group = content.Group; if (IsAuthor(content, userId)) { if (group == null) content.IsDiscussionClosed = !show; else { GroupService.UserInGroup(userId, group, true); content.IsDiscussionClosed = !show; } } else { if (group == null) throw new BusinessLogicException("Недостаточно прав на изменение состояния обсуждения"); var member = GroupService.UserInGroup(userId, group); if (member.State != (byte)GroupMemberState.Moderator) throw new BusinessLogicException("Недостаточно прав на изменение состояния обсуждения"); content.IsDiscussionClosed = !show; } }
public void Restore(Content content, Guid userId) { if (content == null) throw new BusinessLogicException("Не найден указанный контент"); if (!IsAuthor(content, userId)) throw new BusinessLogicException("Восстанавливать контент могут только авторы"); // Описываем исключения, когда нельзя восстановить if (content.State != (byte)ContentState.Deleted) throw new BusinessLogicException("Указанный контент не является удаленным"); if (content is Election) throw new BusinessLogicException("Нельзя восстановить удаленные выборы"); if (content is Poll) throw new BusinessLogicException("Нельзя восстановить удаленное голосование"); if (content is Petition) throw new BusinessLogicException("Нельзя восстановить удаленную петицию"); if (!content.GroupId.HasValue) content.State = (byte)ContentState.Approved; else { var gm = GroupService.UserInGroup(userId, content.Group, true); if (!content.Group.PrivacyEnum.HasFlag(GroupPrivacy.ContentModeration)) { content.State = (byte)ContentState.Approved; if (content is Post) if ((content as Post).IsExternal) content.State = gm.State == (byte)GroupMemberState.Moderator ? (byte)ContentState.Approved : (byte)ContentState.Premoderated; } else content.State = gm.State == (byte)GroupMemberState.Moderator ? (byte)ContentState.Approved : (byte)ContentState.Premoderated; } UpdateContentCache(content); }
public static void Publish(Content content, Guid userId) { _current.Publish(content, userId); }