Exemplo n.º 1
0
        public ActionResult <PaginatedResults <WorkoutDTO> > Get(int firstRecord, short pageSize, bool activeOnly, string nameContains = null)
        {
            try
            {
                //TODO: Consolidate this code somewhere!
                var userId = GetUserID();

                var filter = BuildWorkoutFilter(userId, activeOnly, nameContains);

                int totalCount = _workoutService.GetTotalCount(filter);

                //Blows up after upgrading to EF Core 3.1 from 2.2!
                //More info at https://stackoverflow.com/questions/59677609/problem-with-ef-core-after-migrating-from-2-2-to-3-1
                //Had to add .ToList() to the call below.
                var workouts =
                    _workoutService
                    .Get(firstRecord, pageSize, filter)
                    .OrderBy(x => x.Name);

                var results = workouts.Select((workout) =>
                {
                    return(_workoutDTOAdapter.AdaptFromWorkout(workout));
                });

                var result = new PaginatedResults <WorkoutDTO>(results, totalCount);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }