public async Task <PlaneDetailsDTO> GetDetailsAsync(int id) { var plane = await _unitOfWork.Set <Plane>() .DetailsAsync(id); if (plane == null) { throw new NotFoundException("Plane with such id was not found"); } return(PlaneDetailsDTO.Create(plane)); }
public PlaneDetailsDTO GetDetails(int id) { var plane = _unitOfWork.Set <Plane>() .Details(x => x.Id == id).FirstOrDefault(); if (plane == null) { throw new NotFoundException("Plane with such id was not found"); } return(PlaneDetailsDTO.Create(plane)); }
public async Task <IList <DepartureDetailsDTO> > GetAllDetailsAsync() { var departures = await _unitOfWork.Set <Departure>().DetailsAsync(); var crews = await _unitOfWork.Set <Crew>() .DetailsAsync(x => departures.Any(y => x.Id == y.CrewId)); var planes = await _unitOfWork.Set <Plane>() .DetailsAsync(x => departures.Any(y => x.Id == y.PlaneId)); return(await departures.ToAsyncEnumerable().Select(x => { var plane = planes.First(p => p.Id == x.PlaneId); var crew = crews.First(c => c.Id == x.CrewId); return DepartureDetailsDTO.Create(x, PlaneDetailsDTO.Create(plane), CrewDetailsDTO.Create(crew)); }).ToList()); }
public async Task <DepartureDetailsDTO> GetDetailsAsync(int id) { var departure = await _unitOfWork.Set <Departure>() .DetailsAsync(id); if (departure == null) { throw new NotFoundException("Departure with such id was not found"); } var crew = await _unitOfWork.Set <Crew>() .DetailsAsync(departure.CrewId); var plane = await _unitOfWork.Set <Plane>() .DetailsAsync(departure.PlaneId); return(DepartureDetailsDTO.Create(departure, PlaneDetailsDTO.Create(plane), CrewDetailsDTO.Create(crew))); }