/// <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>
 /// <returns></returns>
 public DomainEditModel GetEditModel(int domainId)
 {
     IDomainDal domainDal = new DomainDal();
     DomainEditModel editModel = new DomainEditModel();
     var domain = domainDal.GetEntity(domainId);
     if (domain != null)
     {
         editModel = new DomainEditModel()
        {
            DomainId = domain.DomainId,
            DomainName = domain.DomainName,
            //DomainPassword=BllUtility.DomainHandler.DecryptDomainPassword(domain.DomainPassword,domain.DomainCode,domain.DomainKey),
            DomainUrl = domain.DomainUrl,
            DomainLevel = domain.DomainLevel,
            IsEnabled = domain.IsEnabled,
            IsSSO = domain.IsSSO,
            SSOUrl = domain.SSOUrl,
            CookieDomain = domain.CookieDomain,
            ParentDomainId = domain.ParentDomainId,
            ReMark = domain.ReMark,
            SSOPoolPoolId = domain.SSOPoolPoolId
        };
     }
     return editModel;
 }
 public ActionResult DomainEdit(DomainEditModel editModel)
 {
     IDomainService service = new DomainService();
     var jsonModel = service.EditDomain(editModel);
     if (jsonModel.Success)
     {
         return Json(new { success = true, msg = "修改成功" }, JsonRequestBehavior.AllowGet);
     }
     else
     {
         return Json(new { success = false, msg = jsonModel.ErrMsg }, JsonRequestBehavior.AllowGet);
     }
 }