public List<UserLevelsDetailsBO> LoadAllUserLevelsByUserID(int userId)
        {
            List<UserLevelsDetailsBO> userLevelsList = new List<UserLevelsDetailsBO>();
                UserLevelsDetailsBO userLevel = new UserLevelsDetailsBO();
                DBEgine dbEgine = new DBEgine();
                try
                {

                    SqlParameter[] parms = new SqlParameter[1];

                    SqlParameter p1 = new SqlParameter();
                    p1.ParameterName = "UserID";
                    p1.SqlDbType = SqlDbType.Int;
                    p1.Direction = ParameterDirection.Input;
                    p1.Value = userId;
                    parms[0] = p1;

                    dbEgine.DBOpen();
                    SqlDataReader drUserLevels = dbEgine.ExecuteReader("UserManagement.UM_LoadUserLevelsByUserID", parms);
                    if (drUserLevels != null && drUserLevels.HasRows)
                    {
                        while (drUserLevels.Read())
                        {
                            userLevel = FillUserLevels(drUserLevels);
                            userLevelsList.Add(userLevel);
                        }
                    }

                    return userLevelsList;
                }
                catch
                {
                    throw;
                }
                finally
                {
                    dbEgine.DBClose();
                }
        }
        public int AddUserLevelsDetails(DBEgine dbEgine,int userId,UserLevelsDetailsBO obj)
        {
            try
                {
                    SqlParameter[] paramArray = new SqlParameter[3];

                    SqlParameter userLevelIDParam = new SqlParameter();
                    userLevelIDParam.ParameterName = "@UserLevelID";
                    userLevelIDParam.SqlDbType = SqlDbType.Int;
                    userLevelIDParam.Direction = ParameterDirection.Input;
                    userLevelIDParam.Value = obj.UserLevelID;
                    paramArray[0] = userLevelIDParam;

                    SqlParameter userIDParam = new SqlParameter();
                    userIDParam.ParameterName = "@UserID";
                    userIDParam.SqlDbType = SqlDbType.Int;
                    userIDParam.Direction = ParameterDirection.Input;
                    userIDParam.Value = userId;
                    paramArray[1] = userIDParam;

                    SqlParameter isPrimaryParam = new SqlParameter();
                    isPrimaryParam.ParameterName = "@IsPrimary";
                    isPrimaryParam.SqlDbType = SqlDbType.Bit;
                    isPrimaryParam.Direction = ParameterDirection.Input;
                    isPrimaryParam.Value = obj.IsPrimary;
                    paramArray[2] = isPrimaryParam;

                    dbEgine.ExecNonQueryStoredProc("UserManagement.UM_AddUserLevelsDetails", paramArray);

                    return obj.UserLevelID;
                }
                catch
                {
                    throw;
                }
        }
 private UserLevelsDetailsBO FillUserLevelsWithName(SqlDataReader reader)
 {
     var userLevels = new UserLevelsDetailsBO();
         userLevels.UserLevelDetailID = reader.GetInt32(reader.GetOrdinal("UserLevelDetailID"));
         userLevels.UserID = reader.GetInt32(reader.GetOrdinal("UserID"));
         userLevels.UserLevelID = reader.GetInt32(reader.GetOrdinal("UserLevelID"));
         userLevels.IsPrimary = reader.GetBoolean(reader.GetOrdinal("IsPrimary"));
         userLevels.UserLevel = reader.GetString(reader.GetOrdinal("UserLevel"));
         return userLevels;
 }