public async Task Save(PassengerDTO passenger) { if (passenger == null) { throw new ArgumentNullException(); } await _repositoryAsync.SaveAsync(passenger.ToPerson()); }
public async Task <BookingDTO> AddPassengerToExistingFlight(string flightNumber, PassengerDTO passenger) { if (string.IsNullOrWhiteSpace(flightNumber)) { return(null); } if (passenger == null) { return(null); } var allFlights = await _flightRepository.GetAllAsync(); var newBookingFlight = allFlights.FirstOrDefault(flight => string.Equals(flight.Number, flightNumber, StringComparison.CurrentCultureIgnoreCase)); if (newBookingFlight == null) { return(null); } await _personRepository.SaveAsync(passenger.ToPerson()); var savedPerson = await _personRepository.GetAsync(passenger.Id); if (savedPerson == null) { return(null); } var newBooking = new Booking { Flight = newBookingFlight, Customer = savedPerson, Passengers = new List <Person> { savedPerson }, Id = _bookingRepository.GetAllAsync().Result.Max(booking => booking.Id) + 1, Number = "WO-999666", DateBooking = DateTime.Now, }; await _bookingRepository.SaveAsync(newBooking); var result = await _bookingRepository.GetAsync(newBooking.Id); return(await Task.FromResult(result.ToBookingDto())); }