public ActionResult DomainAdd(DomainAddModel addModel) { IDomainService service = new DomainService(); var jsonModel = service.AddDomain(addModel); if (jsonModel.Success) { return Json(new { success = true, msg = "添加成功" }, JsonRequestBehavior.AllowGet); } else { return Json(new { success = false, msg = jsonModel.ErrMsg }, JsonRequestBehavior.AllowGet); } }
/// <summary> /// 添加域的实体 /// </summary> /// <param name="model"></param> /// <returns></returns> public JsonModel<Domain> AddDomain(DomainAddModel model) { JsonModel<Domain> jsonModel = new JsonModel<Domain>() { Success = false, ErrMsg = "添加失败", SuccessMsg = "添加成功" }; try { //对实体进行验证 var validate = DotNet.Utils.DataValidate.ValidateHelper<DomainAddModel>.ValidateModel(model); if (!validate.Pass) { jsonModel.ErrMsg = validate.ResultList.FirstOrDefault().ErrorMessage; return jsonModel; } //过滤 model.DomainName = DotNet.Utils.Untility.StringHelper.FilterHtml(model.DomainName); model.ReMark = DotNet.Utils.Untility.StringHelper.FilterHtml(model.ReMark); //生成当前域的级别 int domainLevel = model.DomainLevel; int parentDomainId = model.ParentDomainId; BllUtility.DomainHandler.GetDomainLevel(ref domainLevel, ref parentDomainId); string domainKey = BllUtility.DomainHandler.GetDomainKey(); string domainCode = BllUtility.DomainHandler.GetDomainCode(); string domainPassword = BllUtility.DomainHandler.EncryptDomainPassword(model.DomainPassword, domainCode, domainKey); //构造实体 Domain domain = new Domain() { DomainName = model.DomainName, DomainCode = domainCode, DomainUrl = model.DomainUrl, DomainLevel = domainLevel, ParentDomainId = parentDomainId, IsEnabled = model.IsEnabled, IsSSO = model.IsSSO, SSOUrl = model.SSOUrl, DomainKey = domainKey, DomainPassword = domainPassword, CookieDomain = model.CookieDomain, DelFlag = (int)DelFlagEnum.Noraml, ReMark = model.ReMark, SSOPoolPoolId = model.SSOPoolPoolId }; IDomainDal domainDal = new DomainDal(); var r = domainDal.AddEntity(domain); if (r != null) { jsonModel.Success = true; jsonModel.Data = r; } else { jsonModel.ErrMsg = "数据插入失败"; } } catch (Exception ex) { jsonModel.ErrMsg = ex.Message; } return jsonModel; }