public IActionResult MakeBooking([FromBody] MakeBookingDto booking)
        {
            try
            {
                if (booking == null)
                {
                    return(BadRequest());
                }

                //if (_flightInfoRepository.GetFlightByFlightNumber(booking.FlightNumber) == null)
                if (_flightInfoRepository.GetFlightByFlightNumber(booking.FlightNumber) == null)
                {
                    ModelState.AddModelError("Flight", "Flight does not Exists.");
                    //_logger.LogCritical($"Flight does not Exists for flight Number : {0}", booking.FlightNumber);
                    _logger.LogCritical($"Flight does not Exists for flight Number : {0}", booking.FlightNumber);
                }

                if (_flightInfoRepository.GetPassengersByNameAndMobile(booking.Passenger.Name, booking.Passenger.Mobile) == null)
                {
                    ModelState.AddModelError("Passenge", "Passenger does not Exists.");
                    _logger.LogCritical($"Passenge does not Exists for Passenge Name: {0} and Mobile: {1}", booking.Passenger.Name, booking.Passenger.Mobile);
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var      flightBookingEntity = AutoMapper.Mapper.Map <FlightBooking>(booking);
                DateTime bookingDate         = new DateTime(booking.Date.Year, booking.Date.Month, booking.Date.Day, 0, 0, 0);
                flightBookingEntity.Date = bookingDate;

                flightBookingEntity.Flight = new Flight();
                //flightBookingEntity.Flight.Id = _flightInfoRepository.GetFlightByFlightNumber(booking.FlightNumber).Id;
                flightBookingEntity.Flight.Id = _flightInfoRepository.GetFlightByFlightNumber(booking.FlightNumber).Id;

                flightBookingEntity.Passenger    = new Passenger();
                flightBookingEntity.Passenger.Id = _flightInfoRepository.GetPassengersByNameAndMobile(booking.Passenger.Name, booking.Passenger.Mobile).Id;

                _flightInfoRepository.MakeBooking(flightBookingEntity);

                if (!_flightInfoRepository.Save())
                {
                    _logger.LogCritical("An Error Occured While Handing Your Request.");
                    return(StatusCode(500, "An Error Occured While Handing Your Request."));
                }

                var newBooking = AutoMapper.Mapper.Map <MakeBookingDto>(flightBookingEntity);
                return(CreatedAtRoute("GetBookingById", new { bookingId = flightBookingEntity.Id }, newBooking));
            }
            catch (Exception ex)
            {
                _logger.LogCritical("An Error Occured in MakeBooking: {0} ", ex.ToString());
                return(StatusCode(500, "An Error Occured While Handing Your Request."));
            }
        }
 public IActionResult GetPassengersByNameAndMobile(string passengerName, string mobile)
 {
     try
     {
         Passenger passengerEntities = _flightInfoRepository.GetPassengersByNameAndMobile(passengerName, mobile);
         var       results           = AutoMapper.Mapper.Map <PassengerDto>(passengerEntities);
         if (results == null)
         {
             return(NotFound());
         }
         return(Ok(results));
     }
     catch (Exception ex)
     {
         _logger.LogCritical("An Error Occured While Handing Your Request. {0}", ex.ToString());
         return(StatusCode(500, "An Error Occured While Handing Your Request."));
     }
 }