/// <summary> /// 通行证绑定系统账号 /// </summary> /// <param name="link"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public void PassportLink(SYSPassportLinkDTO link) { if (string.IsNullOrEmpty(link.LoginName) || string.IsNullOrEmpty(link.SystemCode) || string.IsNullOrEmpty(link.UID)) { throw CFException.Create(SYSPassportLinkResult.LoginNameOrUIDNotFound); } try { var passport = _passportRepository.Get(item => item.LoginName == link.LoginName); if (passport.ID == null) { throw CFException.Create(SYSPassportLinkResult.LoginNameInvalid); } var system = _systemRepository.Get(item => item.SystemCode == link.SystemCode); if (system.ID == null) { throw CFException.Create(SYSPassportLinkResult.SystemCodeInvalid); } var account = _accountRepository.Get(item => item.UID == link.UID && item.SystemID == system.ID); if (account.ID == null || account.PassportID != null) { throw CFException.Create(SYSPassportLinkResult.UIDInvalid); } account.PassportID = passport.ID; _accountRepository.Modify(new SYSAccount { ID = account.ID, PassportID = passport.ID }); return; } catch (Exception ex) { throw CFException.Create(SYSPassportLinkResult.Fail, ex.Message); } }
/// <summary> /// 通行证解绑系统账号 /// </summary> /// <param name="link"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public void PassportUnlink(SYSPassportLinkDTO link) { if (string.IsNullOrEmpty(link.LoginName) || string.IsNullOrEmpty(link.SystemCode) || string.IsNullOrEmpty(link.UID)) { throw CFException.Create(SYSPassportLinkResult.LoginNameOrUIDNotFound); } try { var passport = _passportRepository.Get(item => item.LoginName == link.LoginName); if (passport.ID == null) { throw CFException.Create(SYSPassportLinkResult.LoginNameInvalid); } var system = _systemRepository.Get(item => item.SystemCode == link.SystemCode); if (system.ID == null) { throw CFException.Create(SYSPassportLinkResult.SystemCodeInvalid); } var account = _accountRepository.Get(item => item.SystemID == system.ID && item.UID == link.UID); if (account.ID == null || account.PassportID == null) { throw CFException.Create(SYSPassportLinkResult.UIDInvalid); } account.Property.IsDBNull("PassportID", true); _accountRepository.Remove(item => item.SystemID == system.ID && item.PassportID == passport.ID); return; } catch (Exception ex) { throw CFException.Create(SYSPassportLinkResult.Fail, ex.Message, ex); } }