예제 #1
0
        public static ShoeTrackerDbContext WithFitnessProvider(
            this ShoeTrackerDbContext context, 
            long fitnessProviderId, 
            string name)
        {
            var fitnessProvider = new FitnessProvider
            {
                FitnessProviderId = fitnessProviderId,
                Name = name,
                CreatedAt = DateTime.Now
            };

            context.FitnessProviders.Attach(fitnessProvider);

            return context;
        }
        private void CreateNewWorkout(string currentUserId, 
            Workout mapMyFitnessWorkout, 
            IEnumerable<Shoe> shoesNewestFirst,
            string externalWorkoutId, 
            FitnessProvider mapMyFitnessSource)
        {
            const double milesPerMeter = 0.000621371;

            var distanceInMiles = milesPerMeter * mapMyFitnessWorkout.aggregates.distance_total;
            var workoutDate = DateTime.Parse(mapMyFitnessWorkout.start_datetime);
            var workoutName = string.IsNullOrWhiteSpace(mapMyFitnessWorkout.name) ? "N/A" : mapMyFitnessWorkout.name;
            var shoeUsed = GetActiveShoe(shoesNewestFirst, workoutDate);

            var workout = new models.Workout
            {
                UserId = currentUserId,
                ExternalWorkoutId = externalWorkoutId,
                Source = mapMyFitnessSource,
                ImportedAt = DateTime.Now,
                Name = workoutName,
                WorkoutDate = workoutDate,
                Distance = new Decimal(distanceInMiles),
                ShoeUsed = shoeUsed,
                CreatedAt = DateTime.Now
            };

            _dbContext.Workouts.Add(workout);
        }