public ResponseFuncDelete FuncDelete([FromBody] RequestFuncDelete request) { try { FunctionBLL bll = new FunctionBLL(); return(bll.FuncDelete(request)); } catch (Exception ex) { throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public ResponseFuncDelete FuncDelete(RequestFuncDelete request) { ResponseFuncDelete response = new ResponseFuncDelete(); using (cnn = GetConnection()) { var ts = cnn.BeginTransaction(); try { var user = UserInfoGetButAccount(request.Token, ts); string sql = @"WITH CTE(id, name, img, PARENTID) AS (SELECT id,name,img, PARENTID FROM tks_fas_function WHERE id = @Id UNION ALL SELECT B.id,B.name,B.img,B.PARENTID FROM tks_fas_function B INNER JOIN CTE ON B.PARENTID = CTE.id) SELECT * FROM CTE "; var funcs = cnn.Query <TKS_FAS_Function>(sql, new { Id = request.Data.Id }, ts).Select(p => p.Id).ToList(); var inId = "'" + string.Join("','", funcs.ToArray()) + "'"; string delSql = string.Format("delete from tks_fas_function where id in ({0})", inId); var r = cnn.Execute(delSql, null, ts); delSql = string.Format("delete from tks_fas_entity2Function where functionId in ({0})", inId); cnn.Execute(delSql, null, ts); ts.Commit(); response.IsSuccess = true; response.Message = "删除成功"; return(response); } catch (Exception ex) { ts.Rollback(); return(this.DealException(response, ex) as ResponseFuncDelete); } } }