Example #1
0
        private SegmentAreaViewModel GetAreaViewModel(int areaID, int athleteID, int? lbPage)
        {
            var db = new TourModelContainer();
            var dbArea = db.SegmentAreas.Find(areaID);

            return new SegmentAreaViewModel(athleteID, dbArea, lbPage ?? 1);
        }
Example #2
0
        private RegionViewModel GetRegionViewModel(int regionID, int athleteID, int? lbPage)
        {
            var db = new TourModelContainer();
            var dbRegion = db.Regions.Find(regionID);

            return new RegionViewModel(athleteID, dbRegion, lbPage ?? 1);
        }
Example #3
0
        //, string sortBy)
        private SegmentViewModel GetSegmentViewModel(int segmentID, int athleteID, int? lbPage)
        {
            var db = new TourModelContainer();
            var dbSegment = db.Segments.Find(segmentID);

            return new SegmentViewModel(athleteID, dbSegment, lbPage ?? 1);
        }
Example #4
0
 private static void CreateIndex(TourModelContainer context, string field, string table, bool unique = false)
 {
     context.Database.ExecuteSqlCommand(String.Format("CREATE {0}NONCLUSTERED INDEX IX_{1}_{2} ON {1} ({3})",
         unique ? "UNIQUE " : "",
         table,
         field.Replace(",", "_"),
         field));
 }
Example #5
0
        public EffortUpdate(TourModelContainer db, Models.Result dbResult, int segmentID, double elevationGain)
        {
            this.db = db;
            this.dbResult = dbResult;
            this.segmentID = segmentID;
            this.elevationGain = elevationGain;

            LeaderBoards = new List<Models.LeaderBoard>();
            AthleteEffortsList = new Dictionary<int, List<int>>();
        }
Example #6
0
        internal static List<Models.Athlete> Athletes(TourModelContainer context)
        {
            var athletes = new List<Models.Athlete>
            {
                new Models.Athlete { AthleteID = 352657, Name = "Henrik Næss", PrivacyMode = 1, LastUpdated = DateTime.Now },
                new Models.Athlete { AthleteID = 354993, Name = "Fredrik Massey", PrivacyMode = 1, LastUpdated = DateTime.Now },
            };
            athletes.ForEach(s => context.Athletes.Add(s));
            context.SaveChanges();

            return athletes;
        }
Example #7
0
        private static void Init(TourModelContainer context)
        {
            var athletes = AthleteData.Athletes(context);

            var countries = Countries(context);
            var regions = RegionsInNorway(context, countries[0]);

            SegmentData.OsloKlatreKonge(context, regions[0]);
            SegmentData.Baerum(context, regions[1]);
            SegmentData.Asker(context, regions[2]);
            SegmentData.Nesodden(context, regions[3]);
        }
Example #8
0
        public static void CreateAndInitIfEmpty(TourModelContainer context)
        {
            initDB++;
            //if (initDB <= 1)
            //    DeleteDB(context);

            if (!context.Database.Exists())
            {
                context.Database.Create();
                Init(context);
                CreateIndexes(context);
            }
        }
Example #9
0
        private static List<Models.Country> Countries(TourModelContainer context)
        {
            var countries = new List<Models.Country>
            {
                new Models.Country { CountryID = 578, Name = "Norway" },
                new Models.Country { CountryID = 826, Name = "United Kingdom" },
                new Models.Country { CountryID = 840, Name = "United States" },
            };
            countries.ForEach(s => context.Countries.Add(s));
            context.SaveChanges();

            return countries;
        }
Example #10
0
 internal static void Nesodden(TourModelContainer context, Models.Region region)
 {
     var segmentAreas = new List<Models.SegmentArea>
     {
         InitDB.NewSegmentArea(context, region, null, "Berger"),
         InitDB.NewSegmentArea(context, region, null, "Tangen"),
         InitDB.NewSegmentArea(context, region, null, "Fjellstrand"),
         InitDB.NewSegmentArea(context, region, null, "Jaer"),
         InitDB.NewSegmentArea(context, region, null, "Myklerud"),
         InitDB.NewSegmentArea(context, region, null, "Bjørnemyr"),
         InitDB.NewSegmentArea(context, region, null, "Kolbotn"),
         InitDB.NewSegmentArea(context, region, null, "Tårnåsen"),
         InitDB.NewSegmentArea(context, region, null, "Sofiemyr"),
         InitDB.NewSegmentArea(context, region, null, "Greverud"),
         InitDB.NewSegmentArea(context, region, null, "Svartskog"),
     };
     segmentAreas.ForEach(s => context.SegmentAreas.Add(s));
     context.SaveChanges();
 }
Example #11
0
        internal static void Baerum(TourModelContainer context, Models.Region region)
        {
            var segmentAreas = new List<SegmentArea>
            {
                InitDB.NewSegmentArea(context, region, null, "Østerås-Eiksmarka"),
                InitDB.NewSegmentArea(context, region, null, "Hosle nord"),
                InitDB.NewSegmentArea(context, region, null, "Voll"),
                InitDB.NewSegmentArea(context, region, null, "Grav"),
                InitDB.NewSegmentArea(context, region, null, "Hosle sør"),
                InitDB.NewSegmentArea(context, region, null, "Jar"),
                InitDB.NewSegmentArea(context, region, null, "Lysaker"),
                InitDB.NewSegmentArea(context, region, null, "Snarøya"),
                InitDB.NewSegmentArea(context, region, null, "Stabekk"),
                InitDB.NewSegmentArea(context, region, null, "Høvik"),
                InitDB.NewSegmentArea(context, region, null, "Løkeberg-Blommenholm"),
                InitDB.NewSegmentArea(context, region, null, "Haslum"),
                ////InitDB.NewSegmentArea(context, region, null, "Østre Bærumsmarka"),
                InitDB.NewSegmentArea(context, region, null, "Sandvika-Valler"),
                InitDB.NewSegmentArea(context, region, null, "Jong"),
                InitDB.NewSegmentArea(context, region, null, "Kirkerud-Sollihøgda"),
                //InitDB.NewSegmentArea(context, region, null, "Slependen-Tanum"),
                //InitDB.NewSegmentArea(context, region, null, "Dønski-Rud"),
                //InitDB.NewSegmentArea(context, region, null, "Kolsås"),
                //InitDB.NewSegmentArea(context, region, null, "Rykkinn"),
                //InitDB.NewSegmentArea(context, region, null, "Bærums Verk"),
                InitDB.NewSegmentArea(context, region, null, "Lommedalen"),
                // øst-vest, nord/syd
                InitDB.NewSegmentArea(context, region, null, "Krogskogen", SegmentArea.AreaTypeEnum.MountainBike),
                InitDB.NewSegmentArea(context, region, null, "Bærumsmarka", SegmentArea.AreaTypeEnum.MountainBike),
                InitDB.NewSegmentArea(context, region, null, "Vestmarka", SegmentArea.AreaTypeEnum.MountainBike),
            };
            segmentAreas.ForEach(s => context.SegmentAreas.Add(s));
            context.SaveChanges();

            InitArea(context, region, "Slependen-Tanum", new List<int>() { 1355742, 1108129, 1489331, 1128542 });
            InitArea(context, region, "Kolsås", new List<int>() { 1433727, 1225116, 2173825 });
            InitArea(context, region, "Dønski/Rud", new List<int>() { 1518560, 1596245, 1353132 });
            InitArea(context, region, "Rykkinn", new List<int>() { 1637189, 1382813, 1524861, 1354941, 1242445 });
            InitArea(context, region, "Bærums Verk", new List<int>() { 730928, 1797698 });
        }
Example #12
0
 internal static void Asker(TourModelContainer context, Models.Region region)
 {
     var segmentAreas = new List<SegmentArea>
     {
         InitDB.NewSegmentArea(context, region, null, "Nesøya"),
         InitDB.NewSegmentArea(context, region, null, "Nesbru"),
         InitDB.NewSegmentArea(context, region, null, "Billingstad"),
         InitDB.NewSegmentArea(context, region, null, "Hvalstad"),
         InitDB.NewSegmentArea(context, region, null, "Skaugum"),
         InitDB.NewSegmentArea(context, region, null, "Sem"),
         InitDB.NewSegmentArea(context, region, null, "Syverstad"),
         InitDB.NewSegmentArea(context, region, null, "Fusdal"),
         InitDB.NewSegmentArea(context, region, null, "Sentrum"),
         InitDB.NewSegmentArea(context, region, null, "Drengsrud"),
         InitDB.NewSegmentArea(context, region, null, "Vettre"),
         InitDB.NewSegmentArea(context, region, null, "Borgen"),
         InitDB.NewSegmentArea(context, region, null, "Blakstad"),
         InitDB.NewSegmentArea(context, region, null, "Vollen"),
         InitDB.NewSegmentArea(context, region, null, "Heggedal"),
         InitDB.NewSegmentArea(context, region, null, "Solberg"),
     };
     segmentAreas.ForEach(s => context.SegmentAreas.Add(s));
     context.SaveChanges();
 }
Example #13
0
 private static Statistics NewStatistics(TourModelContainer context, string name)
 {
     return new Statistics() { Name = name, AvgGrade = 0, Distance = 0, NoRidden = 0, NoRiders = 0, LastUpdated = DefaultDate };
 }
Example #14
0
 private static bool DeleteDB(TourModelContainer context)
 {
     return context.Database.Delete();
 }
Example #15
0
 private static void CreateIndexes(TourModelContainer context)
 {
     CreateIndex(context, "StartDate", "Efforts", false);
     CreateIndex(context, "ElapsedTime", "Efforts", false); // TODO: Review stil lvalid?
 }
Example #16
0
        internal static void OsloKlatreKonge(TourModelContainer context, Models.Region region)
        {
            var segments = new List<Models.Segment>
            {
                InitDB.NewSegment(context, 632847, "Kongsveien"),
                InitDB.NewSegment(context, 1942901, "Klatringen til Tryvann fra Gressbanen"),
                InitDB.NewSegment(context, 660072, "Grefsenkollen"),
            };
            segments.ForEach(s => context.Segments.Add(s));

            var segmentAreas = new List<SegmentArea>
            {
                InitDB.NewSegmentArea(context, region, segments, "Oslo klatrekonge"),

                InitDB.NewSegmentArea(context, region, null, "Gamle Oslo"),
                InitDB.NewSegmentArea(context, region, null, "Grünerløkka"),
                InitDB.NewSegmentArea(context, region, null, "Sagene"),
                InitDB.NewSegmentArea(context, region, null, "Hanshaugen"),
                InitDB.NewSegmentArea(context, region, null, "Frogner"),
                InitDB.NewSegmentArea(context, region, null, "Ullern"),
                InitDB.NewSegmentArea(context, region, null, "Vestre Aker"),
                InitDB.NewSegmentArea(context, region, null, "Nordre Aker"),
                InitDB.NewSegmentArea(context, region, null, "Bjerke"),
                InitDB.NewSegmentArea(context, region, null, "Grorud"),
                InitDB.NewSegmentArea(context, region, null, "Stovner"),
                InitDB.NewSegmentArea(context, region, null, "Alna"),
                InitDB.NewSegmentArea(context, region, null, "Østensjø"),
                InitDB.NewSegmentArea(context, region, null, "Nordstrand"),
                InitDB.NewSegmentArea(context, region, null, "Søndre Nordstrand"),
                InitDB.NewSegmentArea(context, region, null, "Sentrum"),

                InitDB.NewSegmentArea(context, region, null, "Lillomarka", SegmentArea.AreaTypeEnum.MountainBike),
                InitDB.NewSegmentArea(context, region, null, "Nordmarka syd", SegmentArea.AreaTypeEnum.MountainBike),
                InitDB.NewSegmentArea(context, region, null, "Nordmarka nord", SegmentArea.AreaTypeEnum.MountainBike),
                InitDB.NewSegmentArea(context, region, null, "Østmarka", SegmentArea.AreaTypeEnum.MountainBike),
            };
            segmentAreas.ForEach(s => context.SegmentAreas.Add(s));
            context.SaveChanges();
        }
Example #17
0
 internal static Models.SegmentArea NewSegmentArea(TourModelContainer context, Models.Region region, List<Models.Segment> segments, string name, SegmentArea.AreaTypeEnum areaType = SegmentArea.AreaTypeEnum.Default)
 {
     Models.Result result = null;
     return new SegmentArea { Region = region, Segments = segments, Result = result, Info = NewStatistics(context, name), AreaType = (int)areaType};
 }
Example #18
0
 internal static Models.Segment NewSegment(TourModelContainer context, int segmentID, string name)
 {
     Models.Result result = null;
     return new Models.Segment { SegmentID = segmentID, Result = result, Info = NewStatistics(context, name), };
 }
Example #19
0
 private static List<Models.Region> RegionsInNorway(TourModelContainer context, Models.Country country)
 {
     var regions = new List<Models.Region>
     {
         new Models.Region { CountryID = 578, Info = NewStatistics(context, "Oslo")},
         new Models.Region { CountryID = 578, Info = NewStatistics(context, "Bærum")},
         new Models.Region { CountryID = 578, Info = NewStatistics(context, "Asker")},
         new Models.Region { CountryID = 578, Info = NewStatistics(context, "Nesodden" )},
         new Models.Region { CountryID = 578, Info = NewStatistics(context, "Trondheim")},
     };
     regions.ForEach(s => context.Regions.Add(s));
     context.SaveChanges();
     return regions;
 }
Example #20
0
        private static void InitArea(TourModelContainer context, Models.Region region, string name, List<int> segmentList)
        {
            var segments = new List<Models.Segment>();
            for (int i = 0; i < segmentList.Count; i++ )
            {
                segments.Add(InitDB.NewSegment(context, segmentList[i], name + " #" + i));
            }
            segments.ForEach(s => context.Segments.Add(s));

            context.SegmentAreas.Add(InitDB.NewSegmentArea(context, region, segments, name));
            context.SaveChanges();
        }