public List<Role> GetAllRoles(string sqlWhere)
        {
            List<Role> roles = new List<Role>();
            using (DataCommand cmd = DataCommandManager.GetDataCommand("GetAllRoles"))
            {
                if (!string.IsNullOrEmpty(sqlWhere))
                {
                    cmd.CommandText = cmd.CommandText + " " + sqlWhere;
                }
                using (IDataReader dr = cmd.ExecuteDataReader())
                {
                    while (dr.Read())
                    {
                        Role role = new Role();

                        if (!Convert.IsDBNull(dr["RoleId"]))
                        {
                            role.RoleId = Convert.ToInt32(dr["RoleId"]);
                        }
                        if (!Convert.IsDBNull(dr["RoleName"]))
                        {
                            role.RoleName = dr["RoleName"].ToString();
                        }
                        if (!Convert.IsDBNull(dr["Description"]))
                        {
                            role.Description = dr["Description"].ToString();
                        }
                        roles.Add(role);
                    }
                }
            }
            return roles;
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="roleid"></param>
 /// <returns></returns>
 public Role GetRoleByRoleId(int roleid)
 {
     Role model = new Role();
     //string sql = "select * from Base_Role where RoleId = @PK";
     using (DataCommand cmd = DataCommandManager.GetDataCommand("GetRoleIdByRoleId"))
     {
         cmd.SetParameterValue("@RoleId", roleid);
         using (IDataReader dr = cmd.ExecuteDataReader())
         {
             while (dr.Read())
             {
                 if (!Convert.IsDBNull(dr["RoleId"]))
                 {
                     model.RoleId = (int)dr["RoleId"];
                 }
                 if (!Convert.IsDBNull(dr["RoleName"]))
                 {
                     model.RoleName = (string)dr["RoleName"];
                 }
                 if (!Convert.IsDBNull(dr["SortCode"]))
                 {
                     model.SortCode = (int)dr["SortCode"];
                 }
                 if (!Convert.IsDBNull(dr["Enabled"]))
                 {
                     model.Enabled = (bool)dr["Enabled"];
                 }
                 if (!Convert.IsDBNull(dr["Description"]))
                 {
                     model.Description = (string)dr["Description"];
                 }
             }
         }
     }
     return model;
 }
 public int Update(Role model)
 {
     return _dataAccess.Update(model);
 }
 public int Insert(Role model)
 {
     return _dataAccess.Insert(model);
 }
 public int Update(Role model)
 {
     using (DataCommand cmd = DataCommandManager.GetDataCommand("UpdateRole"))
     {
         cmd.SetParameterValue("@RoleName", model.RoleName);
         cmd.SetParameterValue("@SortCode", model.SortCode);
         cmd.SetParameterValue("@Enabled", model.Enabled);
         cmd.SetParameterValue("@Description", model.Description);
         cmd.SetParameterValue("@RoleId", model.RoleId);
         return cmd.ExecuteNonQuery();
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Insert(Role model)
 {
     using (DataCommand cmd = DataCommandManager.GetDataCommand("InsertRole"))
     {
         cmd.SetParameterValue("@RoleId", KeyGenerator.Instance.GetNextValue("Role"));
         cmd.SetParameterValue("@RoleName", model.RoleName);
         cmd.SetParameterValue("@SortCode", model.SortCode);
         cmd.SetParameterValue("@Enabled", model.Enabled);
         cmd.SetParameterValue("@Description", model.Description);
         return cmd.ExecuteNonQuery();
     }
 }