Exemplo n.º 1
0
        public static int CommitPost(Post p, IGraffitiUser user, bool isFeaturedPost, bool isFeaturedCategory)
        {
            Permission perm   = RolePermissionManager.GetPermissions(p.CategoryId, user);
            bool       isMan  = perm.Publish;
            bool       isEdit = GraffitiUsers.IsAdmin(user);

            if (isMan || isEdit)
            {
                p.IsPublished = (p.PostStatus == PostStatus.Publish);
            }
            else
            {
                p.IsPublished = false;

                if (p.PostStatus != PostStatus.Draft && p.PostStatus != PostStatus.PendingApproval)
                {
                    p.PostStatus = PostStatus.Draft;
                }
            }

            p.ModifiedBy = user.Name;

            if (p.IsNew) //No VERSION WORK, just save it.
            {
                p.Version = 1;
                p.Save(user.Name, SiteSettings.CurrentUserTime);
            }
            else if (p.IsPublished) //Make a copy of the current post, then save this one.
            {
                Post old_Post = new Post(p.Id);

                //if(old_Post.PostStatus == PostStatus.Publish)
                VersionPost(old_Post);

                p.Version = GetNextVersionId(p.Id, p.Version);
                p.Save(user.Name);
            }
            else
            {
                p.Version = GetNextVersionId(p.Id, p.Version);
                VersionPost(p);
                Post.UpdatePostStatus(p.Id, p.PostStatus);
            }

            ProcessFeaturedPosts(p, user, isFeaturedPost, isFeaturedCategory);

            if (p.PostStatus == PostStatus.PendingApproval)
            {
                SendPReqiresApprovalMessage(p, user);
            }
            else if (p.PostStatus == PostStatus.RequiresChanges)
            {
                SendRequestedChangesMessage(p, user);
            }

            return(p.Id);
        }