Beispiel #1
0
        public async Task <List <AvailableViewModel> > CheckAvailability(CheckAvailabilityRequest request, CancellationToken cancellationToken)
        {
            if (request.startDate < DateTime.Now.Date || request.startDate == DateTime.MinValue)
            {
                throw new ArgumentException($"Invalid start date {request.startDate}", nameof(request.startDate));
            }
            if (request.endDate < DateTime.Now.Date || request.startDate == DateTime.MinValue)
            {
                throw new ArgumentException($"Invalid end date {request.endDate}", nameof(request.endDate));
            }
            if (request.numberOfPax < 1)
            {
                throw new ArgumentException($"Passenger count has to be atleast 1 {request.numberOfPax}", nameof(request.numberOfPax));
            }

            var result = new List <AvailableViewModel>();

            for (DateTime date = request.startDate; date.Date <= request.endDate.Date; date = date.AddDays(1))
            {
                var dateValue = await this._flightBookingsRepository.CheckAvailability(date, request.numberOfPax, cancellationToken);

                if (dateValue != null)
                {
                    result.Add(new AvailableViewModel {
                        Date = date, Flights = this._mapper.Map <List <FlightViewModel> >(dateValue)
                    });
                }
            }
            return(result);
        }
Beispiel #2
0
        public async Task <IActionResult> CheckAvailability([FromBody] CheckAvailabilityRequest request, CancellationToken cancellationToken)
        {
            try
            {
                var result = await this._bookingsService.CheckAvailability(request, cancellationToken);

                return(new ObjectResult(result));
            }
            catch (ArgumentException ae)
            {
                return(BadRequest(ae));
            }
        }