示例#1
0
 /// <summary>
 /// 根据角色Id获取角色编辑信息
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public RoleInfoEditModel GetRoleInfoById(string id)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(id))
         {
             throw new Exception("角色Id不能为空!");
         }
         RoleInfoEditModel result = new RoleInfoEditModel();
         DataTable         dt     = _sql.Query("SELECT RoleName,RoleCode FROM RoleInfo WHERE IsDeleted = 0 AND RoleInfoId = @id", new Dictionary <string, object> {
             { "@id", id }
         });
         if (dt != null && dt.Rows.Count > 0)
         {
             result.RoleInfoId = id;
             result.RoleName   = Cast.ConToString(dt.Rows[0]["RoleName"]);
             result.RoleCode   = Cast.ConToString(dt.Rows[0]["RoleCode"]);
         }
         return(result);
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         throw ex;
     }
 }
示例#2
0
 /// <summary>
 /// 创建或更新角色信息
 /// </summary>
 /// <param name="info">角色编辑信息</param>
 /// <returns></returns>
 public string CreateOrUpdateRoleInfo(RoleInfoEditModel info)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(info.RoleName))
         {
             throw new Exception("角色名称不能为空!");
         }
         if (string.IsNullOrWhiteSpace(info.RoleCode))
         {
             throw new Exception("角色编码不能为空!");
         }
         _sql.OpenDb();
         string   result   = string.Empty;
         RoleInfo roleInfo = new RoleInfo();
         info.FillTableWithModel <RoleInfo>(roleInfo);
         if (!string.IsNullOrEmpty(info.RoleInfoId))
         {
             _sql.Update(roleInfo);
             result = Constants.UpdateSuccessMssg;
         }
         else
         {
             DataTable dt = _sql.Query("SELECT RoleName FROM RoleInfo WHERE IsDeleted = 0 AND RoleCode = @code", new Dictionary <string, object> {
                 { "@code", info.RoleCode }
             });
             if (dt != null && dt.Rows.Count > 0)
             {
                 throw new Exception(string.Format("当前角色【{0}:{1}】已存在!", info.RoleCode, Cast.ConToString(dt.Rows[0]["RoleName"])));
             }
             _sql.Create(roleInfo);
             result = Constants.CreateSuccessMssg;
         }
         return(result);
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         throw ex;
     }
     finally
     {
         _sql.CloseDb();
     }
 }