/// <summary> /// 删除域 /// </summary> /// <param name="domainId"></param> /// <returns></returns> public JsonModel<string> DeleteDomain(int domainId) { JsonModel<string> jsonModel = new JsonModel<string>() { Success = false, ErrMsg = "删除失败", SuccessMsg = "删除成功" }; IDomainDal domainDal = new DomainDal(); var domain = domainDal.GetEntity(domainId); if (domain == null) { jsonModel.ErrMsg = "该域不存在"; return jsonModel; } domain.DelFlag = (int)DelFlagEnum.LogicalDelete; var r = domainDal.UpdateEntity(domain); if (r != null && r.DomainId > 0) { jsonModel.Success = true; } return jsonModel; }
/// <summary> /// 修改域 /// </summary> /// <param name="model"></param> /// <returns></returns> public JsonModel<Domain> EditDomain(DomainEditModel model) { JsonModel<Domain> jsonModel = new JsonModel<Domain>() { Success = false, ErrMsg = "修改失败", SuccessMsg = "修改成功" }; //对实体进行验证 var validate = DotNet.Utils.DataValidate.ValidateHelper<DomainEditModel>.ValidateModel(model); if (!validate.Pass) { jsonModel.ErrMsg = validate.ResultList.FirstOrDefault().ErrorMessage; return jsonModel; } //字符过滤 model.ReMark = DotNet.Utils.Untility.StringHelper.FilterHtml(model.ReMark); IDomainDal domainDal = new DomainDal(); var dbDomain = domainDal.GetEntity(model.DomainId); if (dbDomain == null) { jsonModel.ErrMsg = "当前域不存在"; return jsonModel; } //先判断当前域的级别,如果为1级,则没有上一级,否则,就检测上一级是否存在 if (model.DomainLevel > 1) { var parentDomain = domainDal.GetEntity(model.ParentDomainId); if (parentDomain == null) { jsonModel.ErrMsg = "父域不存在"; return jsonModel; } } else { model.DomainLevel = 1; model.ParentDomainId = 0; } int oldPoolId = dbDomain.SSOPoolPoolId; //检测单点登录池是否存在 ISSOPoolDal ssoPoolDal = new SSOPoolDal(); var pool = ssoPoolDal.GetEntity(model.SSOPoolPoolId); if (pool == null) { jsonModel.ErrMsg = "你选择的单点登录池不存在"; return jsonModel; } #region 生成修改的属性 //域密码 //string encryptPassword = BllUtility.DomainHandler.EncryptDomainPassword(model.DomainPassword,dbDomain.DomainCode,dbDomain.DomainKey); dbDomain.DomainName = model.DomainName; dbDomain.DomainUrl = model.DomainUrl; dbDomain.DomainLevel = model.DomainLevel; dbDomain.ParentDomainId = model.ParentDomainId; dbDomain.CookieDomain = model.CookieDomain; dbDomain.IsEnabled = model.IsEnabled; dbDomain.IsSSO = model.IsSSO; dbDomain.SSOUrl = model.SSOUrl; dbDomain.ReMark = model.ReMark; dbDomain.SSOPoolPoolId = model.SSOPoolPoolId; // dbDomain.DomainPassword = encryptPassword; #endregion var r = domainDal.UpdateEntity(dbDomain); if (r != null && r.DomainId > 0) { jsonModel.Success = true; jsonModel.Data = r; } //最后,判断是否修改了池子 if (oldPoolId != dbDomain.SSOPoolPoolId) { //判断池子的主域是否是这个 if (pool.MainDomainId == oldPoolId) { pool.MainDomainId = 0; ssoPoolDal.UpdateEntity(pool); } } return jsonModel; }
/// <summary> /// 开启或者关闭域 /// </summary> /// <param name="domainId"></param> /// <param name="isEnabled"></param> /// <returns></returns> public JsonModel<string> ChangeDomainEnabled(int domainId, int isEnabled) { JsonModel<string> jsonModel = new JsonModel<string>() { Success = false, ErrMsg = "操作失败", SuccessMsg = "操作成功" }; IDomainDal domainDal = new DomainDal(); var domain = domainDal.GetEntity(domainId); if (domain == null || domain.DomainId == 0) { jsonModel.ErrMsg = "当前域不存在"; return jsonModel; } if (!Enum.IsDefined(typeof(IsEnabledEnum), isEnabled)) { jsonModel.ErrMsg = "域的状态不正确"; return jsonModel; } domain.IsEnabled = isEnabled; var r = domainDal.UpdateEntity(domain); if (r != null && r.DomainId > 0) { jsonModel.Success = true; } return jsonModel; }