public List<PriorityLevel> GetPriorityLevels()
        {
            List<PriorityLevel> list = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.PriorityLevel_Select"
               , inputParamMapper: null
               , map: delegate(IDataReader reader, short set)
               {
                   PriorityLevel pl = new PriorityLevel();

                   int startingIndex = 0;

                   pl.Id = reader.GetSafeInt32(startingIndex++);
                   pl.Name = reader.GetSafeString(startingIndex++);

                   if (list == null)
                   {
                       list = new List<PriorityLevel>();
                   }

                   list.Add(pl);
               }
               );
            return list;
        }
        private static PlanFeature MapPlanFeature(IDataReader reader)
        {
            PlanFeature pf = new PlanFeature();

            PriorityLevel pl = new PriorityLevel();

            int startingIndex = 0;

            pf.Id = reader.GetSafeInt32(startingIndex++);
            pf.Title = reader.GetSafeString(startingIndex++);
            pf.Description = reader.GetSafeString(startingIndex++);
            pf.Category = reader.GetSafeInt32(startingIndex++);
            pf.PlanId = reader.GetSafeInt32(startingIndex++);
            pf.DateAdded = reader.GetSafeDateTime(startingIndex++);
            pf.DateModified = reader.GetSafeDateTime(startingIndex++);
            pf.LanguageCode = reader.GetSafeString(startingIndex++);

            pl.Name = reader.GetSafeString(startingIndex++);
            pl.Id = reader.GetSafeInt32(startingIndex++);

            pf.SortOrder = pl;

            return pf;
        }
        public List<UserPlans> GetPlanByUserId(string userId)
        {
            List<UserPlans> list = null;
            List<PlanFeature> featureList = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.UserPlans_SelectByUserId_v3"
               , inputParamMapper: delegate(SqlParameterCollection paramCollection)

               { paramCollection.AddWithValue("@UserId", userId); }

               , map: delegate(IDataReader reader, short set)
               {

                   UserPlans u = new UserPlans();

                   PlanType pt = new PlanType();

                   PlanFeature pf = new PlanFeature();

                   PriorityLevel pl = new PriorityLevel();

                   if (set == 0)
                   {
                       int startingIndex = 0;

                       u.PlanId = reader.GetSafeInt32(startingIndex++);
                       u.Subscribed = reader.GetSafeBool(startingIndex++);
                       u.PlanName = reader.GetSafeString(startingIndex++);
                       u.PlanDescription = reader.GetSafeString(startingIndex++);
                       pt.Id = reader.GetSafeInt32(startingIndex++);
                       pt.Name = reader.GetSafeString(startingIndex++);
                       u.Cost = reader.GetSafeInt32(startingIndex++);
                       u.GoLiveDate = reader.GetSafeDateTime(startingIndex++);
                       u.TagId = reader.GetSafeInt32(startingIndex++);
                       u.TagName = reader.GetSafeString(startingIndex++);

                       u.Type = pt;

                       if (list == null)
                       {
                           list = new List<UserPlans>();
                       }

                       list.Add(u);

                   }

                   if (set == 1)
                   {
                       int startingIndex = 0;

                       pf.Title = reader.GetSafeString(startingIndex++);
                       pf.Description = reader.GetSafeString(startingIndex++);
                       pf.Id = reader.GetSafeInt32(startingIndex++);
                       pf.PlanId = reader.GetSafeInt32(startingIndex++);
                       pf.DateAdded = reader.GetSafeDateTime(startingIndex++);
                       pf.DateModified = reader.GetSafeDateTime(startingIndex++);
                       pf.LanguageCode = reader.GetSafeString(startingIndex++);

                       pl.Name = reader.GetSafeString(startingIndex++);
                       pl.Id = reader.GetSafeInt32(startingIndex++);

                       pf.SortOrder = pl;

                       if (featureList == null)
                       {
                           featureList = new List<PlanFeature>();
                       }

                       featureList.Add(pf);

                   }

               });

            if (featureList != null)
            {
            for (var i = 0; featureList.Count > i; i++)
            {

                for (var e = 0; list.Count > e; e++)
                {
                    if (list[e].PlanId == featureList[i].PlanId)
                    {

                        if (list[e].FeatureInfo == null)
                        {
                            list[e].FeatureInfo = new List<PlanFeature>();
                        }

                        list[e].FeatureInfo.Add(featureList[i]);

                    }
                }

            }
            }

            return list;
        }