Пример #1
0
        public GetBookingResponseDto GetBooking(int propertyId)
        {
            if (propertyId <= 0)
            {
                throw new PmsException("Get Booking call failed.");
            }

            var      queryParams = Request.GetQueryNameValuePairs();
            var      startDate   = queryParams.FirstOrDefault(x => x.Key == "startdate").Value;
            var      endDate     = queryParams.FirstOrDefault(x => x.Key == "enddate").Value;
            var      dtFormats   = new[] { "dd/MM/yyyy", "yyyy-MM-dd", "dd/M/yyyy", "dd/MM/yyyy" };
            DateTime dtStart;
            DateTime dtEnd;

            if (startDate == null || !DateTime.TryParseExact(startDate, dtFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out dtStart))
            {
                throw new PmsException("Incorrect booking start date");
            }

            if (endDate == null || !DateTime.TryParseExact(endDate, dtFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out dtEnd))
            {
                throw new PmsException("Incorrect booking end date");
            }

            var response = new GetBookingResponseDto();

            if (!AppConfigReaderHelper.AppConfigToBool(AppSettingKeys.MockEnabled))
            {
                response.Bookings = _iPmsLogic.GetBooking(propertyId, dtStart, dtEnd);
            }
            else
            {
                //mock data
                response.Bookings = new List <Resources.Entities.Booking>
                {
                    new Booking
                    {
                        CheckinTime  = Convert.ToDateTime(String.Format("{0:s}", DateTime.Now)),
                        CheckoutTime = Convert.ToDateTime(String.Format("{0:s}", DateTime.Now.AddHours(3))),
                        RoomBookings = new List <RoomBooking>
                        {
                            new RoomBooking
                            {
                                Id   = 100,
                                Room = new Room
                                {
                                    Id     = 1,
                                    Number = "Room B"
                                },
                                Guest = new Guest
                                {
                                    Id        = 11,
                                    FirstName = "Tyagi",
                                    LastName  = "Sachin"
                                }
                            },
                            new RoomBooking
                            {
                                Id   = 200,
                                Room = new Room
                                {
                                    Id     = 2,
                                    Number = "Room C"
                                },
                                Guest = new Guest
                                {
                                    Id        = 22,
                                    FirstName = "Sharma",
                                    LastName  = "Sachin"
                                }
                            },
                            new RoomBooking
                            {
                                Id   = 300,
                                Room = new Room
                                {
                                    Id     = 3,
                                    Number = "Room D"
                                },
                                Guest = new Guest
                                {
                                    Id        = 33,
                                    FirstName = "Deepak",
                                    LastName  = "Sachin"
                                }
                            },
                            new RoomBooking
                            {
                                Id   = 400,
                                Room = new Room
                                {
                                    Id     = 4,
                                    Number = "Room E"
                                },
                                Guest = new Guest
                                {
                                    Id        = 44,
                                    FirstName = "Sharma123",
                                    LastName  = "Sachin"
                                }
                            }
                        }
                    }
                };
            }
            return(response);
        }