public BaseTripController(DBConnectionInfo dBConnectionInfo)
 {
     Ctx = new mydrivingDBContext(dBConnectionInfo);
     //Select Random Trip
     GetSampleTrip();
     //Default Constructor
 }
Ejemplo n.º 2
0
        public async Task CreateTrip(DBConnectionInfo dBConnectionInfo)
        {
            ctx = new mydrivingDBContext(dBConnectionInfo);
            //Use to AutoGenerate Trip Number
            Random r = new Random();

            tripCount += ctx.Trips.Count();

            //Initialize Trip
            CurrentTrip = new Trips();
            //Simulation trip selection
            List <string> tripNames = ctx.TripPointSource
                                      .Select(p => p.Name)
                                      .Distinct()
                                      .ToList();

            var tName = tripNames.ElementAt(r.Next(0, tripNames.Count));

            //Choose Random Trip
            tripInfo = ctx.TripPointSource
                       .Where(p => p.Name == tName)
                       .ToList();

            Console.WriteLine($"Sample Trip Selected: {tName}");

            CreateTripPoints(tripInfo.FirstOrDefault().Name);

            //TODO : Do proper Distance Calculation and Add a method to determine Rating
            CurrentTrip.EndTimeStamp = CurrentTrip.TripPoints.Last <TripPoints>().RecordedTimeStamp;
            CurrentTrip.Rating       = 90;
            //TODO : DO BingMaps Call to determine distance
            CurrentTrip.Distance = 5.95;

            //Get Trip POIs and Update Trip Summary Information
            GetTripPois();
            //Update Driver Profile with Trip Data
            UpdateUserProfile();
            //Add trips to DB Instance
            await ctx.Trips.AddAsync(CurrentTrip);

            await ctx.Pois.AddRangeAsync(poiList);

            //Save Changes and Update Database
            await ctx.SaveChangesAsync();

            ctx.Dispose();
        }