Exemplo n.º 1
0
        public IActionResult Delete(DeleteCategoryRequest model)
        {
            if (model == null)
            {
                return this.BadRequest();
            }

            var result = this.CategoryService.Delete(model);

            return this.ApiResponse(result);
        }
Exemplo n.º 2
0
        public OperationResult Delete(DeleteCategoryRequest model)
        {
            using (var conn = this.OpenConnection())
            {
                string sql = @"
UPDATE [Category] SET ParentID=NULL WHERE ParentID IN @IDs;

DELETE FROM [Category] WHERE ID IN @IDs;

DELETE FROM [CategoryArticle] WHERE CategoryID IN @IDs;
";

                var para = new
                {
                    IDs = model.CategoryIDList
                };

                var rows = conn.Execute(sql, para);

                if (rows == 0)
                {
                    return OperationResult.ErrorResult("不存在的分类");
                }

                this.ClearCache();
                return OperationResult.SuccessResult();
            }
        }