Exemplo n.º 1
0
        /// <summary>
        /// Expand the list if needed. For example, ID=0 is "all age-groupers" so we need to get all age group Ids
        /// </summary>
        /// <param name="selectedAgeGroupIds"></param>
        /// <returns></returns>
        static public IList <int> Expand(IList <int> selectedAgeGroupIds)
        {
            if (selectedAgeGroupIds.Count > 0 && selectedAgeGroupIds.Contains(0)) //id==0
            {
                using (var db = new RaceAnalysisDbContext())
                {
                    /*note: a little kludgy and not the way I started coding it, but got errors try to include Pro in the Except List. */
                    //       var pro = db.AgeGroups.Where(a => a.Value.ToLower() == "pro");
                    //       var allExceptPro = db.AgeGroups.Except(pro).Select(a => a.AgeGroupId);
                    //       var list = allExceptPro.ToList();
                    //       if (selectedAgeGroupIds.Contains(pro.First().AgeGroupId))
                    //           list.Insert(0,pro.First().AgeGroupId);
                    var list = db.AgeGroups.OrderBy(a => a.DisplayOrder).Select(a => a.AgeGroupId).ToList();

                    return(list);
                }
            }
            else
            {
                using (var db = new RaceAnalysisDbContext())
                {
                    var list = db.AgeGroups.OrderBy(a => a.DisplayOrder)
                               .Where(a => selectedAgeGroupIds.Contains(a.AgeGroupId))
                               .Select(a => a.AgeGroupId).ToList();

                    return(list);
                }
            }
        }
Exemplo n.º 2
0
 private void PopulateAgeGroupsAndGenders()
 {
     using (var db = new RaceAnalysisDbContext())
     {
         AvailableAgeGroups = GetAvailableAgeGroups(db);
         AvailableGenders   = db.Genders.ToList();
     }
 }
Exemplo n.º 3
0
        private List <int> GetDefaultGenders()
        {
            using (var db = new RaceAnalysisDbContext())
            {
                var query = db.Genders
                            .Where(t => t.Value == "M" ||
                                   t.Value == "F").Select(t => t.GenderId);

                return(query.ToList());
            }
        }
Exemplo n.º 4
0
 //if selectedId==0 then select all
 static public IList <int> Expand(IList <int> selectedGenders)
 {
     if (selectedGenders.Count > 0 && selectedGenders.Contains(0)) //id==0
     {
         using (var db = new RaceAnalysisDbContext())
         {
             return(db.Genders.Select(g => g.GenderId).ToList());
         }
     }
     else
     {
         return(selectedGenders);
     }
 }
Exemplo n.º 5
0
        private List <AgeGroup> GetAvailableAgeGroups(RaceAnalysisDbContext db)
        {
            var ag = db.AgeGroups.OrderBy(a => a.DisplayOrder).ToList();

            return(ag);
        }
Exemplo n.º 6
0
        private void PopulateRaces(string distance, string sortOrder)
        {
            switch (distance)
            {
            case "140.6":
                distance = "140.6";
                break;

            case "70.3":
                distance = "70.3";
                break;

            default:
                distance = null;
                break;
            }
            Distance = distance;

            IQueryable <Race> races;

            using (var db = new RaceAnalysisDbContext())
            {
                //note: need to include the Conditions info because the AvailableRaces property is being
                //used to populate the Stats. Don't know if
                //if I like this choice but going with it for now. Other option is to populate the stats using
                //available races from the dbContext.
                races = db.Races.Include("Conditions");

                if (!String.IsNullOrEmpty(distance))
                {
                    races = races.Where(r => r.Distance == distance);
                }



                switch (sortOrder)
                {
                case "name_desc":
                    races = races.OrderByDescending(r => r.LongDisplayName);
                    break;

                case "Date":
                    races = races.OrderBy(r => r.RaceDate);
                    break;

                case "date_desc":
                    races = races.OrderByDescending(r => r.RaceDate);
                    break;

                default:      // Name ascending
                    races = races.OrderBy(r => r.LongDisplayName);
                    break;
                }
                Sort = sortOrder;

                foreach (var r in races)
                {
                    r.RaceId = r.RaceId.ToUpper(); //this way we only do it here and not everywhere in the code
                }

                AvailableRaces = races.ToList();
            }
        }