Пример #1
0
        public ActionResult <Result> Delete([FromRoute] string articleLangId)
        {
            //获取用户信息
            string user_id = Token.GetUserId(HttpContext.Request.Headers["Authorization"].ToString().Substring(7));
            TUser  user    = userServer.Retrieve(new TUser()
            {
                UserId = user_id
            });

            if (user.Super != 1)
            {
                throw new ResultException("无权操作");
            }

            TArticleLang lang = articleServer.Retrieve(new TArticleLang {
                ArticleLangId = articleLangId
            });

            if (lang == null)
            {
                throw new ResultException("文章不存在");
            }

            if (lang.UserId != user.UserId)
            {
                throw new ResultException("无法删除他人的文章");
            }

            TArticle p_article = articleServer.RetrieveMainArticle(new TArticle {
                ArticleId = lang.ArticleId
            });

            //如果这篇文章下只有一篇语言文章则连父级也删除
            if (articleServer.RetrieveArticlesByArticleId(p_article.ArticleId).Count() == 1)
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    articleServer.Delete(lang);
                    articleServer.DeleteMainArticle(p_article);

                    scope.Complete();
                }
            }
            else
            {
                articleServer.Delete(lang);
            }

            return(new Result(200, "成功"));
        }