Ejemplo n.º 1
0
        public async Task <OfmForGetQueryResult <WorkoutOfmForGet> > GetById(int id, WorkoutOfmResourceParameters resourceParameters, Guid ownerGuid)
        {
            var ofmForGetResult = new OfmForGetQueryResult <WorkoutOfmForGet>();

            ofmForGetResult = await AsyncGetOfmGuardClause.ValidateGetById(ofmForGetResult, resourceParameters.Fields); // Todo: Validate additional *Include* query parameters

            if (ofmForGetResult.ErrorMessages.Count > 0)
            {
                return(ofmForGetResult);
            }

            var workoutLinqToEntity = Repo.LinqToEntityQueryable();

            workoutLinqToEntity = workoutLinqToEntity
                                  .Include(i => i.MapExerciseWorkout)
                                  .Include(i => i.WorkoutHistories);

            if (resourceParameters.IncludeMapsExerciseWorkout.ToBool())
            {
                workoutLinqToEntity =
                    workoutLinqToEntity
                    .Include(i => i.MapExerciseWorkout)
                    .ThenInclude(i => i.Exercise);
            }

            var workout = workoutLinqToEntity.FirstOrDefault(f => f.Id == id && f.OwnerGuid == ownerGuid);

            if (workout == null)
            {
                return(ofmForGetResult);
            }

            ofmForGetResult.ReturnedTOfmForGet = Mapper.Map <Workout, WorkoutOfmForGet>(workout);

            if (resourceParameters.IncludeMapsExerciseWorkout.ToBool() && workout.MapExerciseWorkout.Count() > 0)
            {
                ofmForGetResult.ReturnedTOfmForGet.MapsExerciseWorkout = Mapper.Map <List <MapExerciseWorkoutOfmForGet> >(workout.MapExerciseWorkout.ToList());
            }

            return(ofmForGetResult);
        }
Ejemplo n.º 2
0
        public async Task <OfmForGetQueryResult <WorkoutHistoryOfmForGet> > GetById(int id, WorkoutHistoryOfmResourceParameters resourceParameters, Guid ownerGuid)
        {
            var ofmForGetResult = new OfmForGetQueryResult <WorkoutHistoryOfmForGet>();

            ofmForGetResult = await AsyncGetOfmGuardClause.ValidateGetById(ofmForGetResult, resourceParameters.Fields); // Todo: Validate additional *Include* query parameters

            if (ofmForGetResult.ErrorMessages.Count > 0)
            {
                return(ofmForGetResult);
            }

            var workoutHistoryLinqToEntity = Repo.LinqToEntityQueryable();

            if (resourceParameters.IncludeExerciseHistories.ToBool())
            {
                workoutHistoryLinqToEntity =
                    workoutHistoryLinqToEntity
                    .Include(i => i.ExerciseHistories)
                    .ThenInclude(i => i.Exercise);

                if (resourceParameters.IncludeWeightLiftingSets.ToBool())
                {
                    workoutHistoryLinqToEntity =
                        workoutHistoryLinqToEntity
                        .Include(i => i.ExerciseHistories)
                        .ThenInclude(i => i.WeightLiftingSets);

                    if (resourceParameters.IncludePreviousExerciseHistories.ToBool())
                    {
                        workoutHistoryLinqToEntity = workoutHistoryLinqToEntity
                                                     .Include(i => i.ExerciseHistories)
                                                     .ThenInclude(i => i.WeightLiftingSets)
                                                     .Include(i => i.ExerciseHistories)
                                                     .ThenInclude(i => i.PreviousExerciseHistory)
                                                     .ThenInclude(i => i.WeightLiftingSets);
                    }
                }

                if (resourceParameters.IncludeCardioSets.ToBool())
                {
                    workoutHistoryLinqToEntity =
                        workoutHistoryLinqToEntity
                        .Include(i => i.ExerciseHistories)
                        .ThenInclude(i => i.CardioSets);

                    if (resourceParameters.IncludePreviousExerciseHistories.ToBool())
                    {
                        workoutHistoryLinqToEntity =
                            workoutHistoryLinqToEntity
                            .Include(i => i.ExerciseHistories)
                            .ThenInclude(i => i.CardioSets)
                            .Include(i => i.ExerciseHistories)
                            .ThenInclude(i => i.PreviousExerciseHistory)
                            .ThenInclude(i => i.CardioSets);
                    }
                }
            }

            var workoutHistory = workoutHistoryLinqToEntity.Include(i => i.Workout).FirstOrDefault(f => f.Id == id && f.OwnerGuid == ownerGuid);

            if (workoutHistory == null)
            {
                return(ofmForGetResult);
            }

            ofmForGetResult.ReturnedTOfmForGet = Mapper.Map <WorkoutHistoryOfmForGet>(workoutHistory);

            return(ofmForGetResult);
        }