public async Task <Collection <ComponentRead> > Handle(GetAllComponentsRequest request, CancellationToken cancellationToken) { var components = context.Bikes .Where(x => x.Id == request.BikeId) .SelectMany(bike => bike.Components); var componentReads = await components .ProjectTo <ComponentRead>(mappingConfig) .ToListAsync(cancellationToken); return(new Collection <ComponentRead>(componentReads)); }
public async Task <ICollection <ComponentRead> > Handle(GetAllComponentsRequest request, CancellationToken cancellationToken) { if (await context.Bikes.FindAsync(new object[] { request.BikeId }, cancellationToken) is null) { throw new NotFoundException($"Bike {request.BikeId} cannot be found"); } var components = context.Bikes .Where(x => x.Id == request.BikeId) .SelectMany(bike => bike.Components); var componentReads = await components .ProjectTo <ComponentRead>(mappingConfig) .ToListAsync(cancellationToken); return(new Collection <ComponentRead>(componentReads)); }