Exemple #1
0
 public _PostViewModel(Post post)
 {
     if (post != null)
     {
         Title = post.Title;
         Text = post.Text;
     }
 }
 public UserEditPostViewModel(Post post)
 {
     PostId = post.Id;
     Title = post.Title;
     Text = post.Text;
     IsDraft = post.State == (byte)ContentState.Draft;
     TagTitles = TagsHelper.ConvertTagListToString(post.Tags);
 }
        public GroupEditPostViewModel(Post post)
        {
            PostId = post.Id;
            Title = post.Title;
            Text = post.Text;
            IsDraft = post.State == (byte)ContentState.Draft;
            TagTitles = TagsHelper.ConvertTagListToString(post.Tags);

            GroupId = post.Group.Id;
            GroupUrl = post.Group.Url;
            GroupName = post.Group.Name;
            IsContentModeration = post.Group.PrivacyEnum.HasFlag(GroupPrivacy.ContentModeration);
        }
Exemple #4
0
        public Post CreatePost(Guid?groupId, Guid?authorId, string title, string text, string tagsString, bool isDraft, bool isExternal)
        {
            var post = new Post
            {
                AuthorId     = authorId,
                GroupId      = groupId,
                IsExternal   = isExternal,
                CreationDate = DateTime.Now,
                PublishDate  = !isDraft ? DateTime.Now : (DateTime?)null,
                Tags         = new List <Tag>(),
                Title        = title,
                Text         = text
            };

            foreach (var tag in TagsHelper.ConvertStringToTagList(tagsString, post.GroupId))
            {
                post.Tags.Add(tag);
            }

            if (!authorId.HasValue)
            {
                if (!groupId.HasValue)
                {
                    throw new BusinessLogicException("Укажите принадлежность поста к группе или пользователю");
                }

                post.State = isDraft ? (byte)ContentState.Draft : (byte)ContentState.Approved;
            }
            else
            {
                if (groupId.HasValue)
                {
                    var group = DataService.PerThread.GroupSet.SingleOrDefault(x => x.Id == groupId.Value);
                    if (group == null)
                    {
                        throw new BusinessLogicException("Указан неверный идентификатор группы");
                    }

                    var gm = GroupService.UserInGroup(authorId.Value, group, true);

                    if (isDraft)
                    {
                        post.State = (byte)ContentState.Draft;
                    }
                    else
                    {
                        if (group.PrivacyEnum.HasFlag(GroupPrivacy.ContentModeration))
                        {
                            post.State = gm.State == (byte)GroupMemberState.Moderator
                                             ? (byte)ContentState.Approved
                                             : (byte)ContentState.Premoderated;
                        }
                        else
                        {
                            if (isExternal)
                            {
                                post.State = gm.State == (byte)GroupMemberState.Moderator
                                                 ? (byte)ContentState.Approved
                                                 : (byte)ContentState.Premoderated;
                            }
                            else
                            {
                                post.State = (byte)ContentState.Approved;
                            }
                        }
                    }
                }
                else
                {
                    post.State = isDraft ? (byte)ContentState.Draft : (byte)ContentState.Approved;
                }
            }

            DataService.PerThread.ContentSet.AddObject(post);
            DataService.PerThread.SaveChanges();
            UpdateContentCache(post);

            return(post);
        }
        public Post CreatePost(Guid? groupId, Guid? authorId, string title, string text, string tagsString, bool isDraft, bool isExternal)
        {
            var post = new Post
            {
                AuthorId = authorId,
                GroupId = groupId,
                IsExternal = isExternal,
                CreationDate = DateTime.Now,
                PublishDate = !isDraft ? DateTime.Now : (DateTime?)null,
                Tags = new List<Tag>(),
                Title = title,
                Text = text
            };

            foreach (var tag in TagsHelper.ConvertStringToTagList(tagsString, post.GroupId))
                post.Tags.Add(tag);

            if (!authorId.HasValue)
            {
                if (!groupId.HasValue)
                    throw new BusinessLogicException("Укажите принадлежность поста к группе или пользователю");

                post.State = isDraft ? (byte)ContentState.Draft : (byte)ContentState.Approved;
            }
            else
            {
                if (groupId.HasValue)
                {
                    var group = DataService.PerThread.GroupSet.SingleOrDefault(x => x.Id == groupId.Value);
                    if (group == null)
                        throw new BusinessLogicException("Указан неверный идентификатор группы");

                    var gm = GroupService.UserInGroup(authorId.Value, group, true);

                    if (isDraft)
                        post.State = (byte)ContentState.Draft;
                    else
                    {
                        if (group.PrivacyEnum.HasFlag(GroupPrivacy.ContentModeration))
                            post.State = gm.State == (byte)GroupMemberState.Moderator
                                             ? (byte)ContentState.Approved
                                             : (byte)ContentState.Premoderated;
                        else
                        {
                            if (isExternal)
                                post.State = gm.State == (byte)GroupMemberState.Moderator
                                                 ? (byte)ContentState.Approved
                                                 : (byte)ContentState.Premoderated;
                            else
                                post.State = (byte)ContentState.Approved;
                        }
                    }
                }
                else
                    post.State = isDraft ? (byte)ContentState.Draft : (byte)ContentState.Approved;

            }

            DataService.PerThread.ContentSet.AddObject(post);
            DataService.PerThread.SaveChanges();
            UpdateContentCache(post);

            return post;
        }