コード例 #1
0
        public AjaxResponse DoDeletePost(int idPost, Guid settingsID)
        {
            _forumManager = Community.Forum.ForumManager.Settings.ForumManager;
            var resp = new AjaxResponse {
                rs2 = idPost.ToString()
            };

            var post = ForumDataProvider.GetPostByID(TenantProvider.CurrentTenantID, idPost);

            if (post == null)
            {
                resp.rs1 = "0";
                resp.rs3 = Resources.ForumUCResource.ErrorAccessDenied;
                return(resp);
            }

            if (!_forumManager.ValidateAccessSecurityAction(ForumAction.PostDelete, post))
            {
                resp.rs1 = "0";
                resp.rs3 = Resources.ForumUCResource.ErrorAccessDenied;
                return(resp);
            }

            try
            {
                var result = RemoveDataHelper.RemovePost(post);
                if (result == DeletePostResult.Successfully)
                {
                    resp.rs1 = "1";
                    resp.rs3 = Resources.ForumUCResource.SuccessfullyDeletePostMessage;
                }
                else if (result == DeletePostResult.ReferencesBlock)
                {
                    resp.rs1 = "0";
                    resp.rs3 = Resources.ForumUCResource.ExistsReferencesChildPosts;
                }
                else
                {
                    resp.rs1 = "0";
                    resp.rs3 = Resources.ForumUCResource.ErrorDeletePost;
                }
            }
            catch (Exception e)
            {
                resp.rs1 = "0";
                resp.rs3 = HttpUtility.HtmlEncode(e.Message);
            }

            return(resp);
        }
コード例 #2
0
        public ForumTopicPostWrapper DeletePost(int postid)
        {
            var post = ForumDataProvider.GetPostByID(TenantId, postid);

            if (post == null || !ForumManager.Settings.ForumManager.ValidateAccessSecurityAction(ForumAction.PostDelete, post))
            {
                throw new SecurityException(ForumResource.ErrorAccessDenied);
            }

            var result = RemoveDataHelper.RemovePost(post);

            if (result != DeletePostResult.Successfully)
            {
                throw new Exception("DeletePostResult: " + result);
            }

            return(new ForumTopicPostWrapper(post));
        }