コード例 #1
0
        public async Task <IEnumerable <ExerciseApiModel> > GetExercises()
        {
            var exercises = await exerciseRepository.GetAllExercisesAsync();

            return(exercises.Select(e => new ExerciseApiModel
            {
                Id = e.Id,
                Name = e.Name,
                Image = e.Image_1
            }));
        }
コード例 #2
0
        public async Task Handle(ActivitiesCopiedFromWorkout notification, CancellationToken cancellationToken)
        {
            var allExercises = await _exerciseRepository.GetAllExercisesAsync();

            await _activitiesCopiedFromWorkoutTableStorageHandler
            .StoreActivities(
                notification.WorkoutId,
                notification.Activities.Select(a => new Bodybuildr.Domain.Workouts.Activity
            {
                ExerciseId   = a.ExerciseId,
                ExerciseName = allExercises.SingleOrDefault(e => a.ExerciseId == e.Id)?.Name ?? string.Empty,
                Id           = a.Id,
                Sets         = a.Sets
            }));
        }
コード例 #3
0
        public async Task Handle(ActivityCompleted notification, CancellationToken cancellationToken)
        {
            Workout workout = await GetWorkoutAsync(notification.UserId, notification.WorkoutId);

            var activity = new Activity(notification.WorkoutId, notification.ActivityId)
            {
                WorkoutStarted = workout.StartDateTime,
                ExerciseId     = notification.ExerciseId,
                Added          = notification.Added,
                UserId         = notification.UserId,
                Sets           = notification.Sets?.ToArray(),
                Rating         = notification.Rating
            };
            await _activityTableHandler.InsertOrReplace(activity);

            var exercises = await _exerciseRepository.GetAllExercisesAsync();

            var workoutActivity = new WorkoutActivity
            {
                ActivityId   = notification.ActivityId,
                Added        = notification.Added,
                ExerciseId   = notification.ExerciseId,
                SetCount     = notification.Sets.Count(),
                ExerciseName = exercises.SingleOrDefault(s => s.Id == notification.ExerciseId).Name,
            };
            var activities    = workout.Activities.ToList();
            var existingIndex = activities.Select((x, idx) => new { x.ActivityId, idx })
                                .Where(p => p.ActivityId == notification.ActivityId)
                                .Select(p => p.idx + 1)
                                .FirstOrDefault() - 1;

            if (existingIndex == -1)
            {
                activities.Add(workoutActivity);
            }
            else
            {
                activities[existingIndex] = workoutActivity;
            }
            workout.Activities    = activities.ToArray();
            workout.ActivityCount = workout.Activities.Count();
            workout.Version       = notification.Version;
            await _workoutTableHandler.InsertOrReplace(workout);
        }
コード例 #4
0
        private async Task <IEnumerable <StrongR.ReadStack.Workouts.TableStorage.Exercise> > GetExercises()
        {
            var exercises = await _exerciseRepository.GetAllExercisesAsync();

            return(exercises.OrderBy(e => e.Name));
        }