public static SysUser QuerySysUserByRecordId(string recordId) { if (string.IsNullOrWhiteSpace(recordId)) { throw new ArgumentNullException("recordId"); } ISysUser factory = SysUserFactory.GetFactory(); return(factory.QuerySysUserByRecordId(recordId)); }
public static bool Delete(string recordId) { if (string.IsNullOrWhiteSpace(recordId)) { throw new ArgumentNullException("recordId"); } ISysUser factory = SysUserFactory.GetFactory(); SysUser model = factory.QuerySysUserByRecordId(recordId); if (model == null) { throw new MyException("待删除的用户不存在"); } if (model.IsDefaultUser == YesOrNo.Yes) { throw new MyException("该用户为系统默认用户不能删除"); } ISysUserRolesMapping roleFactory = SysUserRolesMappingFactory.GetFactory(); ISysUserScopeMapping scopeFactory = SysUserScopeMappingFactory.GetFactory(); using (DbOperator dbOperator = ConnectionManager.CreateConnection()) { try { dbOperator.BeginTransaction(); bool result = factory.Delete(recordId, dbOperator); if (!result) { throw new MyException("添加用户信息失败"); } roleFactory.DeleteByUserId(recordId, dbOperator); scopeFactory.DeleteByUserID(recordId, dbOperator); dbOperator.CommitTransaction(); if (result) { OperateLogServices.AddOperateLog(OperateType.Delete, string.Format("RecordId:{0}", recordId)); } return(true); } catch { dbOperator.RollbackTransaction(); throw; } } }