public async Task <IActionResult> GetProviders(int id, [FromQuery] GetCourseProvidersRequest request) { try { var result = await _mediator.Send(new GetTrainingCourseProvidersQuery { Id = id, Location = request.Location, SortOrder = (short)request.SortOrder, Lat = request.Lat, Lon = request.Lon, ShortlistUserId = request.ShortlistUserId }); var mappedProviders = result.Providers .Select(c => new GetTrainingCourseProviderListItem().Map(c, result.Course.SectorSubjectAreaTier2Description, result.Course.Level, request.DeliveryModes, request.ProviderRatings, result.Location?.GeoPoint != null)) .Where(x => x != null) .OrderByProviderScore(request.DeliveryModes) .ToList(); var model = new GetTrainingCourseProvidersResponse { TrainingCourse = result.Course, TrainingCourseProviders = mappedProviders, Total = result.Total, TotalFiltered = mappedProviders.Count, Location = new GetLocationSearchResponseItem { Name = result.Location?.Name, Location = new GetLocationSearchResponseItem.LocationResponse { GeoPoint = result.Location?.GeoPoint } }, ShortlistItemCount = result.ShortlistItemCount, ShowEmployerDemand = result.ShowEmployerDemand }; return(Ok(model)); } catch (Exception e) { _logger.LogError(e, $"Error attempting to get a training course {id}"); return(BadRequest()); } }
public async Task <IActionResult> GetProviders(int id) { try { var result = await _mediator.Send(new GetTrainingCourseProvidersQuery { Id = id }); var model = new GetTrainingCourseProvidersResponse { TrainingCourse = result.Course, TrainingCourseProviders = result.Providers.Select(c => (GetTrainingCourseProviderListItem)c).ToList(), Total = result.Total }; return(Ok(model)); } catch (Exception e) { _logger.LogError(e, $"Error attempting to get a training course {id}"); return(BadRequest()); } }