/// <summary> /// 删除group拥有的权限、删除group表的数据 /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task DeleteAsync(long id) { LinGroup linGroup = await _groupRepository.Where(r => r.Id == id).FirstAsync(); if (linGroup.IsNull()) { throw new LinCmsException("分组不存在,删除失败", ErrorCode.NotFound, StatusCodes.Status404NotFound); } if (linGroup.IsStatic) { throw new LinCmsException("无法删除静态权限组!"); } bool exist = await _userGroupRepository.Select.AnyAsync(r => r.GroupId == id); if (exist) { throw new LinCmsException("分组下存在用户,不可删除", ErrorCode.Inoperable); } _freeSql.Transaction(() => { //_freeSql.Select<LinGroupPermission>(new { GroupId = id }).ToDelete().ExecuteDeleted(); //_freeSql.Select<LinGroup>().Where(r => r.Id == id).ToDelete().ExecuteDeleted(); _freeSql.Delete <LinGroupPermission>(new LinGroupPermission { GroupId = id }).ExecuteDeleted(); _freeSql.Delete <LinGroup>(new LinGroup { Id = id }).ExecuteDeleted(); }); }
public ResultDto Delete(int id) { LinGroup linGroup = _freeSql.Select <LinGroup>(new { id = id }).First(); if (linGroup.IsNull()) { throw new LinCmsException("分组不存在,删除失败", ErrorCode.NotFound, StatusCodes.Status404NotFound); } if (linGroup.IsStatic) { throw new LinCmsException("无法删除静态角色!"); } bool exist = _freeSql.Select <LinUser>().Any(r => r.GroupId == id); if (exist) { throw new LinCmsException("分组下存在用户,不可删除", ErrorCode.Inoperable); } _freeSql.Transaction(() => { //删除group拥有的权限 _freeSql.Delete <LinAuth>().Where("group_id=?GroupId", new LinAuth() { GroupId = id }).ExecuteAffrows(); //删除group表 _freeSql.Delete <LinGroup>(new { id = id }).ExecuteAffrows(); }); return(ResultDto.Success("删除分组成功")); }