Exemple #1
0
        private async Task SaveRidePings(List <Ping> pings)
        {
            var ride = await GetCurrentRide();

            if (!(ride is Ride))
            {
                ride = new Ride()
                {
                    TimeFrom = pings[0].Time,
                    TimeTo   = pings[pings.Count - 1].Time
                };
                rideRepository.Insert(ride);
                await rideRepository.SaveAsync();
            }
            else
            {
                ride.TimeTo = pings[pings.Count - 1].Time;
                rideRepository.Update(ride);
                await rideRepository.SaveAsync();
            }

            // Try to get the day
            var day = await dayRepository.GetByRide(ride);

            if (!(day is Day))
            {
                day = new Day()
                {
                    TimeFrom = pings[0].Time,
                    TimeTo   = pings[pings.Count - 1].Time,
                    RideId   = ride.Id
                };
                dayRepository.Insert(day);
                await dayRepository.SaveAsync();
            }
            else
            {
                day.TimeTo = pings[pings.Count - 1].Time;
                dayRepository.Update(day);
                await dayRepository.SaveAsync();
            }

            foreach (var ping in pings)
            {
                ping.RideId     = ride.Id;
                ping.LocationId = null;
                ping.Processed  = 1;
                ping.DayId      = day.Id;
                pingRepository.Update(ping);
            }

            await pingRepository.SaveAsync();

            cache.ClearCache();

            // Save the ride distance to speed up some statistics
            ride = await rideRepository.GetByIdFull(ride.Id);

            ride.ResetDistance();
            rideRepository.Update(ride);
            await rideRepository.SaveAsync();
        }