Exemple #1
0
        public CrewDetailsDTO GetDetails(int id)
        {
            var crew = _unitOfWork.Set <Crew>()
                       .Details(x => x.Id == id).FirstOrDefault();

            if (crew == null)
            {
                throw new NotFoundException("Crew with such id was not found");
            }
            return(CrewDetailsDTO.Create(crew));
        }
Exemple #2
0
        public async Task <CrewDetailsDTO> GetDetailsAsync(int id)
        {
            var crew = await _unitOfWork.Set <Crew>()
                       .DetailsAsync(id);

            if (crew == null)
            {
                throw new NotFoundException("Crew with such id was not found");
            }
            return(CrewDetailsDTO.Create(crew));
        }
Exemple #3
0
        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());
        }
Exemple #4
0
        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)));
        }