Exemplo n.º 1
0
 /// <summary>
 /// 添加一个域
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public Domain AddEntity(Domain entity)
 {
     try
     {
         using (var connection = ConnectionFactory.GetMasterSql())
         {
             string sql = @"Insert into B_Domain (DomainName,DomainCode,DomainKey,DomainPassword,DomainUrl,DomainLevel,ParentDomainId,IsEnabled,IsSSO,SSOUrl,CookieDomain,DelFlag,ReMark,SSOPoolPoolId) values(@DomainName,@DomainCode,@DomainKey,@DomainPassword,@DomainUrl,@DomainLevel,@ParentDomainId,@IsEnabled,@IsSSO,@SSOUrl,@CookieDomain,@DelFlag,@ReMark,@SSOPoolPoolId);  select @@identity;";
             var id = connection.ExecuteScalar<int>(sql, new { DomainName = entity.DomainName, DomainCode = entity.DomainCode, DomainUrl = entity.DomainUrl, DomainLevel = entity.DomainLevel, ParentDomainId = entity.ParentDomainId, IsEnabled = entity.IsEnabled, IsSSO = entity.IsSSO, SSOUrl = entity.SSOUrl, DomainKey = entity.DomainKey, DomainPassword = entity.DomainPassword, CookieDomain = entity.CookieDomain, DelFlag = (int)DelFlagEnum.Noraml, ReMark = entity.ReMark, SSOPoolPoolId = entity.SSOPoolPoolId });
             var domain = connection.Query<Domain>(@"Select * from B_Domain where DomainId=@DomainId", new { DomainId = id }).FirstOrDefault();
             return domain;
         }
     }
     catch
     {
         return null;
     }
 }
Exemplo n.º 2
0
        /// <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;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 修改域的数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Domain UpdateEntity(Domain entity)
        {
            try
            {
                using (var connection = ConnectionFactory.GetMasterSql())
                {
                    var dbDomain = connection.Query<Domain>(@"Select * from B_Domain where DomainId=@DomainId", new { DomainId = @entity.DomainId }).FirstOrDefault();
                    if (dbDomain == null)
                    {
                        return null;
                    }

                    string sql = @"Update B_Domain set DomainName=@DomainName,DomainUrl=@DomainUrl,DomainLevel=@DomainLevel,ParentDomainId=@ParentDomainId,IsEnabled=@IsEnabled,IsSSO=@IsSSO,SSOUrl=@SSOUrl,DomainKey=@DomainKey,DomainPassword=@DomainPassword,CookieDomain=@CookieDomain,DelFlag=@DelFlag,ReMark=@ReMark,SSOPoolPoolId=@SSOPoolPoolId where DomainId=@DomainId";
                    var r = connection.Execute(sql, new { DomainName = entity.DomainName, DomainUrl = entity.DomainUrl, DomainLevel = entity.DomainLevel, ParentDomainId = entity.ParentDomainId, IsEnabled = entity.IsEnabled, IsSSO = entity.IsSSO, SSOUrl = entity.SSOUrl, DomainKey = entity.DomainKey,DomainPassword=entity.DomainPassword, CookieDomain = entity.CookieDomain, DelFlag = entity.DelFlag, ReMark = entity.ReMark, SSOPoolPoolId = entity.SSOPoolPoolId, DomainId = entity.DomainId });
                    if (r > 0)
                    {
                        var model = connection.Query<Domain>(@"Select * from B_Domain where DomainId=@DomainId", new { DomainId = @entity.DomainId }).FirstOrDefault();
                        return model;
                    }
                    else
                    {
                        return null;
                    }

                }
            }
            catch
            {
                return null;
            }
        }