public async Task <IResultModel> Delete(Guid id) { var exist = await _repository.ExistsAsync(id); if (!exist) { return(ResultModel.Failed("角色不存在")); } exist = await _accountRoleRepository.ExistsByRole(id); if (exist) { return(ResultModel.Failed("有账户绑定了该角色,请先删除对应绑定关系")); } _uow.BeginTransaction(); var result = await _repository.SoftDeleteAsync(id); if (result) { result = await _roleMenuRepository.DeleteByRoleId(id); if (result) { result = await _roleMenuButtonRepository.DeleteByRole(id); if (result) { _uow.Commit(); } } } return(ResultModel.Result(result)); }
public async Task<IResultModel> Delete(Guid id) { var role = await _repository.GetAsync(id); if (role == null) return ResultModel.Failed("角色不存在"); if (role.IsSpecified) return ResultModel.Failed("指定角色不允许删除"); var exist = await _accountRoleRepository.ExistsByRole(id); if (exist) return ResultModel.Failed("有账户绑定了该角色,请先删除对应绑定关系"); using (var uow = _dbContext.NewUnitOfWork()) { var result = await _repository.SoftDeleteAsync(id, uow); if (result) { result = await _roleMenuRepository.DeleteByRoleId(id, uow); if (result) { result = await _roleMenuButtonRepository.DeleteByRole(id, uow); if (result) { uow.Commit(); } } } return ResultModel.Result(result); } }
public async Task <IResultModel> Delete(Guid id) { var exist = await _repository.ExistsAsync(id); if (!exist) { return(ResultModel.Failed("角色不存在")); } exist = await _accountRoleRepository.ExistsByRole(id); if (exist) { return(ResultModel.Failed("有账户绑定了该角色,请先删除对应绑定关系")); } var result = await _repository.SoftDeleteAsync(id); return(ResultModel.Result(result)); }
public async Task <IResultModel> Delete(Guid id) { var role = await _repository.GetAsync(id); if (role == null) { return(ResultModel.Failed("角色不存在")); } if (role.IsSpecified) { return(ResultModel.Failed("指定角色不允许删除")); } var exist = await _accountRoleRepository.ExistsByRole(id); if (exist) { return(ResultModel.Failed("有账户绑定了该角色,请先删除对应绑定关系")); } using (var tran = _repository.BeginTransaction()) { var result = await _repository.SoftDeleteAsync(id, tran); if (result) { result = await _roleMenuRepository.DeleteByRoleId(id, tran); if (result) { result = await _roleMenuButtonRepository.DeleteByRole(id, tran); if (result) { tran.Commit(); } } } return(ResultModel.Result(result)); } }