コード例 #1
0
        public ActionResult Delete(int id)
        {
            var post = MiscService.GetById(id);

            if (post is null)
            {
                return(ResultData(null, false, "杂项页已经被删除!"));
            }

            var srcs = post.Content.MatchImgSrcs().Where(s => s.StartsWith("/"));

            foreach (var path in srcs)
            {
                try
                {
                    System.IO.File.Delete(Path.Combine(HostEnvironment.WebRootPath + path));
                }
                catch (IOException)
                {
                }
            }

            bool b = MiscService.DeleteByIdSaved(id);

            return(ResultData(null, b, b ? "删除成功" : "删除失败"));
        }