Example #1
0
        public async Task <HttpStatusCode> BookingHotels(RouteDto route)
        {
            await logger.WriteLogAsync($"{DateTime.Now} - A request has come for booking a hotels");

            var bookingIds = new List <int>();

            foreach (HotelDto hotel in route.Hotels)
            {
                var hotelUrl = BookingServiceUrls.HOTEL_URL;

                var data = new BookingHotelDto
                {
                    hotelId        = hotel.HotelId,
                    personId       = route.PersonId,
                    dateDeparture  = hotel.DateDeparture,
                    dateArrive     = hotel.DateArrive,
                    countOfPersons = route.CountOfPersonsAdults + route.CountOfPersonsChildren
                };
                var body = JsonConvert.SerializeObject(data);

                try
                {
                    var bookingId = await SendRequest(body, hotelUrl);

                    bookingIds.Add(bookingId);
                }
                catch (HttpRequestException)
                {
                    await logger.WriteLogAsync($"{DateTime.Now} - Hotel service is not available");

                    return(HttpStatusCode.ServiceUnavailable);
                }
            }

            var key = (route.PersonId, BookingType.Hotel);

            _db.AddOrUpdate(key, bookingIds);

            await logger.WriteLogAsync($"{DateTime.Now} - The hotel booking data is preserved in the database");

            return(HttpStatusCode.OK);
        }
 public int Post(int id, [FromBody] BookingHotelDto dto)
 {
     return(id + 100);
 }