Example #1
0
 internal void CreateCleaning(CleaningDTO cleaning)
 {
     if (!HotelApiClient.GetInstance().CreateCleaning(cleaning))
     {
         MessageBox.Show("gg");
     }
 }
Example #2
0
        public AddResult SaveClient(ClientDTO client, string oldTel)
        {
            if (!DataValidation.ValidateTelNum(client.TelNum))
            {
                return(AddResult.InvalidInput);
            }

            if (!string.IsNullOrEmpty(client.Passport))
            {
                if (!DataValidation.ValidatePassport(client.Passport))
                {
                    return(AddResult.InvalidInput);
                }
            }

            var res = HotelApiClient.GetInstance().UpdateClient(client, oldTel);

            if (res == System.Net.HttpStatusCode.NoContent)
            {
                Storage.Instance.ChangeAllClients(client);
                return(AddResult.Success);
            }
            if (res == System.Net.HttpStatusCode.Conflict)
            {
                return(AddResult.AlreadyCreated);
            }

            return(AddResult.Error);
        }
Example #3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            ContentWindow   contentWindow   = new ContentWindow();
            NavigationModel navigationModel = new NavigationModel(contentWindow);

            NavigationManager.Instance.Initialize(navigationModel);
            contentWindow.Show();
            if (AUTHORIZATION_STUB != null)
            {
                var authResp = HotelApiClient.GetInstance().Login(AUTHORIZATION_STUB.Login, AUTHORIZATION_STUB.Password);
                if (authResp != null)
                {
                    var userRole = authResp.User.Role;
                    Storage.Instance.ChangeUser(new User(LoginModel.RightsDictionary[userRole]));

                    NavigationManager.Instance.Navigate(ModesEnum.Main);
                }
            }
            else
            {
                navigationModel.Navigate(ModesEnum.Login);
            }
        }
        public AddResult CreateNewPersonnel(UserCreateDTO user, UserRoles role)
        {
            if (!DataValidation.ValidateTelNum(user.TelNumber))
            {
                return(AddResult.InvalidInput);
            }
            if (!DataValidation.ValidatePassport(user.Passport))
            {
                return(AddResult.InvalidInput);
            }
            if (!DataValidation.ValidatePassport(user.EmplBook))
            {
                return(AddResult.InvalidInput);
            }

            user.Role = role;
            var res = HotelApiClient.GetInstance().CreatePersonnel(user);

            if (res == System.Net.HttpStatusCode.NoContent)
            {
                //Storage.Instance.ChangeAllClients(clientDTO);
                return(AddResult.Success);
            }
            if (res == System.Net.HttpStatusCode.Conflict)
            {
                return(AddResult.AlreadyCreated);
            }

            return(AddResult.Error);
        }
Example #5
0
        public PayResult AddPayment(PaymentTypes paymentType, string amount)
        {
            var valid = double.TryParse(amount, out var amountParsed);

            if (!valid)
            {
                return(PayResult.InvalidInput);
            }

            if (amountParsed > BookingModel.CalculateToPay(Storage.Instance.SelectedBooking))
            {
                return(PayResult.TooMuch);
            }

            var id = Storage.Instance.SelectedBooking.BookingId;

            if (HotelApiClient.GetInstance().AddPayment(id, paymentType, amountParsed))
            {
                var booking = HotelApiClient.GetInstance().GetBookingById(id);
                Storage.Instance.ChangeBooking(booking);

                return(PayResult.Success);
            }

            return(PayResult.Error);
        }
 public List <RoomStatisticsDTO> GetStatistics(DateTime dateFrom, DateTime dateTo)
 {
     if (dateFrom > dateTo)
     {
         MessageBox.Show("Початкова дата пізніше кінцевої!");
     }
     return(HotelApiClient.GetInstance().GetRoomsStats(dateFrom, dateTo));
 }
Example #7
0
        public void ProcessBookingSelection(int bookingId)
        {
            var res = HotelApiClient.GetInstance().GetBookingById(bookingId);

            Storage.Instance.ChangeBooking(res);

            NavigationManager.Instance.Navigate(ModesEnum.Booking);
        }
        public ActionResult Index(FormCollection form,SearchCriteriaViewModel searchcriteria )
        {
            try
            {
                string[] type = form["pas.type"].Split(',');
                string[] age = form["pas.age"].Split(',');
                string[] name = form["pas.name"].Split(',');
                string[] surname = form["pas.surname"].Split(',');
                string[] roomId = form["pas.roomId"].Split(',');

                HotelApiClient client = new HotelApiClient();
                ConfirmRoom confirmRoom = new ConfirmRoom();
                confirmRoom.details = new List<RoomDetail>();
                for (int i = 0; i < type.Count(); i++)
                    confirmRoom.details.Add(new RoomDetail((com.hotelbeds.distribution.hotel_api_sdk.helpers.RoomDetail.GuestType)Enum.Parse(typeof(com.hotelbeds.distribution.hotel_api_sdk.helpers.RoomDetail.GuestType), type[i]), int.Parse(age[i]), name[i], surname[i], int.Parse(roomId[i])));

                string rateKey = (string)Session["ratekey"];
                BookingCheck bookingCheck = new BookingCheck();
                bookingCheck.addRoom(rateKey, confirmRoom);
                CheckRateRQ checkRateRQ = bookingCheck.toCheckRateRQ();

                if (checkRateRQ != null)
                {
                    CheckRateRS responseRate = client.doCheck(checkRateRQ);
                    if (responseRate != null && responseRate.error == null)
                    {
                        com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking booking = new com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking();
                        booking.createHolder("Rosetta", "Pruebas");
                        booking.clientReference = "SDK Test";
                        booking.remark = "***SDK***TESTING";

                        booking.addRoom(rateKey, confirmRoom);
                        BookingRQ bookingRQ = booking.toBookingRQ();
                        if (bookingRQ != null)
                        {
                            BookingRS responseBooking = client.confirm(bookingRQ);

                            if (responseBooking != null && responseBooking.error == null && responseBooking.booking != null)

                                ViewBag.BookingRef = responseBooking.booking.reference;

                        }
                        else
                        {
                            if (responseRate.error != null)
                            {
                                ViewBag.Error = responseRate.error.message;

                            }
                        }
                    }
                }

                return View(searchcriteria);
            }
            catch (Exception exp)
            { return Content(exp.Message); }
        }
Example #9
0
 public bool CreateNewBooking(DateTime dateFrom, DateTime dateTo, int num, string telNum, string commentText)
 {
     if (HotelApiClient.GetInstance().CreateBooking(dateFrom, dateTo, num, telNum, commentText))
     {
         Storage.Instance.ChangeBookings();
         return(true);
     }
     return(false);
 }
Example #10
0
        public List <Hotel> Search(BedBankSearchDto searchCriteria)
        {
            HotelApiClient client = new HotelApiClient();
            StatusRS       status = client.status();

            List <Hotel> hotels = new List <Hotel>();

            if (status != null && status.error == null)
            {
                //List<Tuple<string, string>> param;

                Availability avail = new Availability();
                avail.checkIn  = searchCriteria.StartDate;
                avail.checkOut = searchCriteria.EndDate;
                if (searchCriteria.Address != null && searchCriteria.Address != string.Empty)
                {
                    avail.destination = searchCriteria.Address;
                }
                avail.zone      = 90;
                avail.language  = "CAS";
                avail.shiftDays = 2;
                AvailRoom room = new AvailRoom();
                room.adults   = Convert.ToInt32(searchCriteria.TotalGuest);
                room.children = 0;
                room.details  = new List <RoomDetail>();
                room.adultOf(30);
                room.adultOf(30);
                avail.rooms.Add(room);
                room          = new AvailRoom();
                room.adults   = 2;
                room.children = 0;
                room.details  = new List <RoomDetail>();
                room.adultOf(30);
                room.adultOf(30);
                avail.rooms.Add(room);
                //AT_WEB = 0,
                //AT_HOTEL = 1,
                //INDIFFERENT = 2
                avail.payed = Availability.Pay.AT_WEB;
                AvailabilityRQ availabilityRQ = avail.toAvailabilityRQ();
                if (availabilityRQ != null)
                {
                    AvailabilityRS responseAvail = client.doAvailability(availabilityRQ);

                    if (responseAvail != null && responseAvail.hotels != null && responseAvail.hotels.hotels != null && responseAvail.hotels.hotels.Count > 0)
                    {
                        int hotelsAvailable = responseAvail.hotels.hotels.Count;
                        hotels = responseAvail.hotels.hotels;
                        //var abc = JsonConvert.SerializeObject(responseAvail, Formatting.Indented, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore });
                    }
                }
            }
            return(hotels);
        }
Example #11
0
        public bool Cancel(BookingDTO booking)
        {
            if (HotelApiClient.GetInstance().SetBookingStatus(booking.BookingId, BookingStates.Canceled))
            {
                var _ = HotelApiClient.GetInstance().GetBookingById(booking.BookingId);
                Storage.Instance.ChangeBooking(_);

                return(true);
            }
            return(false);
        }
Example #12
0
        public bool Edit(BookingDTO booking, DateTime from)
        {
            booking.StartDate = from;
            if (HotelApiClient.GetInstance().EditBooking(booking))
            {
                var _ = HotelApiClient.GetInstance().GetBookingById(booking.BookingId);
                Storage.Instance.ChangeBooking(_);

                return(true);
            }
            return(false);
        }
Example #13
0
        public AvailabilityRS GetHotelDetails(AvailabilityRQ request)
        {
            //Logger.Instance.LogFunctionEntry(this.GetType().Name, "GetHotelDetails");
            AvailabilityRS responseHotelDetail = new AvailabilityRS();
            List <Hotel>   hotels        = new List <Hotel>();
            HotelApiClient client        = new HotelApiClient();
            StatusRS       status        = client.status();
            AvailabilityRS responseAvail = null;

            try
            {
                if (status != null && status.error == null)
                {
                    Availability avail = new Availability();
                    avail.checkIn       = Convert.ToDateTime(request.stay.checkIn);
                    avail.checkOut      = Convert.ToDateTime(request.stay.checkOut);
                    avail.includeHotels = new List <int>();
                    foreach (var item in request.hotels.hotel)
                    {
                        avail.includeHotels.Add(item);
                    }
                    AvailRoom room = new AvailRoom();
                    foreach (var occupant in request.occupancies)
                    {
                        room.adults        = Convert.ToInt32(occupant.adults);
                        room.numberOfRooms = Convert.ToInt32(occupant.rooms);
                    }
                    room.details = new List <RoomDetail>();
                    for (int i = 0; i < room.adults; i++)
                    {
                        room.adultOf(30);
                    }

                    avail.rooms.Add(room);
                    AvailabilityRQ availabilityRQ = avail.toAvailabilityRQ();
                    if (availabilityRQ == null)
                    {
                        throw new Exception("Availability RQ can't be null", new ArgumentNullException());
                    }
                    responseAvail = client.doAvailability(availabilityRQ);
                    return(responseAvail);
                }
            }
            catch (Exception)
            {
                throw;
            }

            //Logger.Instance.LogFunctionExit(this.GetType().Name, "GetHotelDetails");
            return(responseHotelDetail);
        }
Example #14
0
        public void ProcessRoomSelection(int roomNumber)
        {
            var room = HotelApiClient.GetInstance().GetRoom(roomNumber);

            var data = new RoomDisplayData
            {
                CameFrom = ModesEnum.Main,
                Room     = room,
                Mode     = DisplayModes.Editing
            };

            Storage.Instance.ChangeRoomDisplayData(data);

            NavigationManager.Instance.Navigate(ModesEnum.Room);
        }
Example #15
0
        public void GoToClient(ClientAnalisedDTO selectedClient)
        {
            var client = HotelApiClient.GetInstance().GetClient(selectedClient.TelNum);

            var data = new ClientDisplayData
            {
                Client   = client,
                Mode     = DisplayModes.Editing,
                CameFrom = ModesEnum.Statistic
            };

            Storage.Instance.ChangeClientDisplayData(data);

            NavigationManager.Instance.Navigate(ModesEnum.Client);
        }
Example #16
0
        public int CreateNewRoom(RoomDTO room, Contracts.Bookings.RoomType selectedType)
        {
            room.Type = selectedType;
            var res = HotelApiClient.GetInstance().CreateRoom(room);

            if (res == System.Net.HttpStatusCode.NoContent)
            {
                Storage.Instance.ChangeBookings();
                return(1);
            }
            if (res == System.Net.HttpStatusCode.Conflict)
            {
                return(2);
            }

            return(0);
        }
Example #17
0
        public bool Login(string login, string pwd)
        {
            var authResp = HotelApiClient.GetInstance().Login(login, pwd);

            if (authResp == null)
            {
                return(false);
            }

            var userRole = authResp.User.Role;

            Storage.Instance.ChangeUser(new User(RightsDictionary[userRole]));

            if (userRole == UserRoles.Maid)
            {
                NavigationManager.Instance.Navigate(ModesEnum.Maid);
            }
            else
            {
                NavigationManager.Instance.Navigate(ModesEnum.Main);
            }

            return(true);
        }
Example #18
0
        public AvailabilityRS GetAvailability <TReq, TRes>(AvailabilityRQ request)
        {
            //Logger.Instance.LogFunctionEntry(this.GetType().Name, "GetAvailability");
            List <Hotel>   hotels        = new List <Hotel>();
            HotelApiClient client        = new HotelApiClient();
            StatusRS       status        = client.status();
            AvailabilityRS responseAvail = null;

            try
            {
                //if (status?.error != null)
                if (status != null && status.error == null)
                {
                    responseAvail = client.doAvailability(request);
                }
            }
            catch (Exception)
            {
                throw;
            }

            //Logger.Instance.LogFunctionExit(this.GetType().Name, "GetAvailability");
            return(responseAvail);
        }
Example #19
0
 internal List <ReportItem> GetReportItems(DateTime selectedDate)
 {
     return(HotelApiClient.GetInstance().GetReport(selectedDate));
 }
Example #20
0
 public TodayBookingsViewModel()
 {
     BookList = HotelApiClient.GetInstance().GetTodayBook();
 }
Example #21
0
 public List <ClientDTO> GetClientsSuitList()
 {
     return(HotelApiClient.GetInstance().GetAnalisedSuitClients());
 }
Example #22
0
 public List <RoomDTO> GetRoomsList(DateTime dateFrom, DateTime dateTo, int places)
 {
     return(HotelApiClient.GetInstance().GetFreeRooms(dateFrom, dateTo, places));
 }
Example #23
0
 public List <ClientDTO> GetClientsList()
 {
     return(HotelApiClient.GetInstance().GetAllClients());
 }
Example #24
0
 internal List <CleaningDTO> GetCleanings()
 {
     return(HotelApiClient.GetInstance().GetAllCleanings());
 }
Example #25
0
        public ObservableCollection <RoomInfo> ChangeInfoTable(DateTime dateFrom, DateTime dateTo)
        {
            var inp = HotelApiClient.GetInstance().RoomInfos(dateFrom, dateTo);

            return(new ObservableCollection <RoomInfo>(inp));
        }
Example #26
0
        static void Main(string[] args)
        {
            try
            {
                HotelApiClient client = new HotelApiClient();
                StatusRS       status = client.status();

                if (status != null && status.error == null)
                {
                    Console.WriteLine("StatusRS: " + status.status);
                }
                else if (status != null && status.error != null)
                {
                    Console.WriteLine("StatusRS: " + status.status + " " + status.error.code + ": " + status.error.message);
                    return;
                }
                else if (status == null)
                {
                    Console.WriteLine("StatusRS: Is not available.");
                    return;
                }

                List <Tuple <string, string> > param;


                Availability avail = new Availability();
                avail.checkIn     = DateTime.Now.AddDays(10);
                avail.checkOut    = DateTime.Now.AddDays(13);
                avail.destination = "PMI";
                avail.zone        = 90;
                avail.language    = "CAS";
                avail.shiftDays   = 2;
                AvailRoom room = new AvailRoom();
                room.adults   = 1;
                room.children = 1;
                room.details  = new List <RoomDetail>();
                room.adultOf(30);
                room.childOf(4);
                room.numberOfRooms = 1;
                avail.rooms.Add(room);
                room          = new AvailRoom();
                room.adults   = 2;
                room.children = 0;
                room.details  = new List <RoomDetail>();
                room.adultOf(30);
                room.adultOf(30);
                room.numberOfRooms = 2;
                avail.rooms.Add(room);
                avail.payed = Availability.Pay.AT_WEB;
                //avail.ofTypes = new HashSet<hotel_api_model.auto.common.SimpleTypes.AccommodationType>();
                //avail.ofTypes.Add(hotel_api_model.auto.common.SimpleTypes.AccommodationType.HOTEL);
                //avail.ofTypes.Add(hotel_api_model.auto.common.SimpleTypes.AccommodationType.APARTMENT);

                //avail.minCategory = 4;
                //avail.limitHotelsTo = 10;
                //avail.numberOfTripAdvisorReviewsHigherThan = 2;
                //avail.tripAdvisorScoreHigherThan = 2

                //avail.matchingKeywords = new HashSet<int>();
                //avail.matchingKeywords.Add(34);
                //avail.matchingKeywords.Add(81);
                //avail.keywordsMatcher = Availability.Matcher.ALL;

                //avail.includeHotels = new List<int>();
                //avail.includeHotels.Add(111637);
                //avail.includeHotels.Add(2818);
                //avail.includeHotels.Add(138465);
                //avail.includeHotels.Add(164471);

                //avail.excludeHotels = new List<int>();
                //avail.excludeHotels.Add(187013);
                //avail.excludeHotels.Add(188330);

                //avail.useGiataCodes = false;
                //avail.limitHotelsTo = 250;
                //avail.limitRoomsPerHotelTo = 5;
                //avail.limitRatesPerRoomTo = 5;
                //avail.ratesHigherThan = 50;
                //avail.ratesLowerThan = 350;

                //avail.hbScoreHigherThan = 3;
                //avail.hbScoreLowerThan = 5;
                //avail.numberOfHBReviewsHigherThan = 50;

                //avail.tripAdvisorScoreHigherThan = 1;
                //avail.tripAdvisorScoreLowerThan = 4;
                //avail.numberOfHBReviewsHigherThan = 50;

                //avail.withinThis = new Availability.Circle() { latitude = 2.646633999999949, longitude = 39.57119, radiusInKilometers = 50 };
                //avail.withinThis = new Availability.Square() { northEastLatitude = 45.37680856570233, northEastLongitude = -2.021484375, southWestLatitude = 38.548165423046584, southWestLongitude = 8.658203125 };

                //avail.includeBoards = new List<string>();
                //avail.includeBoards.Add("R0-E10");
                //avail.includeBoards.Add("BB-E10");
                //avail.excludeBoards = new List<string>();
                //avail.excludeBoards.Add("RO");

                //avail.includeRoomCodes = new List<string>();
                //avail.includeRoomCodes.Add("DBL.ST");
                //avail.includeRoomCodes.Add("DBL.SU");
                ////avail.includeRoomCodes.AddRange(new string[]{ "DBL.ST", "DBL.SU" });
                //avail.excludeRoomCodes = new List<string>();
                //avail.excludeRoomCodes.Add("TPL.ST");

                AvailabilityRQ availabilityRQ = avail.toAvailabilityRQ();
                if (availabilityRQ == null)
                {
                    throw new Exception("Availability RQ can't be null", new ArgumentNullException());
                }

                Console.WriteLine("Availability Request:");
                Console.WriteLine(JsonConvert.SerializeObject(availabilityRQ, Formatting.Indented, new JsonSerializerSettings()
                {
                    DefaultValueHandling = DefaultValueHandling.Ignore
                }));

                AvailabilityRS responseAvail = client.doAvailability(availabilityRQ);

                if (responseAvail != null && responseAvail.hotels != null && responseAvail.hotels.hotels != null && responseAvail.hotels.hotels.Count > 0)
                {
                    Console.WriteLine(string.Format("Availability answered with {0} hotels!", responseAvail.hotels.hotels.Count));
                    Console.WriteLine(JsonConvert.SerializeObject(responseAvail, Formatting.Indented, new JsonSerializerSettings()
                    {
                        DefaultValueHandling = DefaultValueHandling.Ignore
                    }));

                    //  ***********************************
                    //  Try to check reservation with rate
                    //  ***********************************

                    Hotel  firstHotel = responseAvail.hotels.hotels.First();
                    string rateKey    = string.Empty;

                    for (int r = 0; r < firstHotel.rooms.Count && String.IsNullOrEmpty(rateKey); r++)
                    {
                        for (int rk = 0; firstHotel.rooms[r].rates != null && rk < firstHotel.rooms[r].rates.Count && String.IsNullOrEmpty(rateKey); rk++)
                        {
                            rateKey = firstHotel.rooms[r].rates[rk].rateKey;
                        }
                    }

                    if (String.IsNullOrEmpty(rateKey))
                    {
                        Console.WriteLine("No hotel available");
                        return;
                    }

                    Console.WriteLine("Checking reservation with rate " + rateKey);

                    ConfirmRoom confirmRoom = new ConfirmRoom();
                    confirmRoom.details = new List <RoomDetail>();
                    confirmRoom.detailed(RoomDetail.GuestType.ADULT, 30, "NombrePasajero1", "ApellidoPasajero1", 1);
                    confirmRoom.detailed(RoomDetail.GuestType.ADULT, 30, "NombrePasajero2", "ApellidoPasajero2", 1);

                    BookingCheck bookingCheck = new BookingCheck();
                    bookingCheck.addRoom(rateKey, confirmRoom);
                    CheckRateRQ checkRateRQ = bookingCheck.toCheckRateRQ();

                    if (checkRateRQ != null)
                    {
                        CheckRateRS responseRate = client.doCheck(checkRateRQ);
                        if (responseRate != null && responseRate.error == null)
                        {
                            Console.WriteLine("CheckRate Response:");
                            Console.WriteLine(JsonConvert.SerializeObject(responseRate, Formatting.Indented, new JsonSerializerSettings()
                            {
                                DefaultValueHandling = DefaultValueHandling.Ignore
                            }));

                            com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking booking = new com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking();
                            booking.createHolder("Rosetta", "Pruebas");
                            booking.clientReference = "SDK Test";
                            booking.remark          = "***SDK***TESTING";

                            //NOTE: ONLY LIBERATE (PAY AT HOTEL MODEL) USES PAYMENT DATA NODES. FOR OTHER PRICING MODELS THESE NODES MUST NOT BE USED.
                            booking.cardType       = "VI";
                            booking.cardNumber     = "4444333322221111";
                            booking.expiryDate     = "0620";
                            booking.cardCVC        = "0620";
                            booking.email          = "*****@*****.**";
                            booking.phoneNumber    = "654654654";
                            booking.cardHolderName = "AUTHORISED";

                            booking.addRoom(rateKey, confirmRoom);
                            BookingRQ bookingRQ = booking.toBookingRQ();
                            if (bookingRQ != null)
                            {
                                BookingRS responseBooking = client.confirm(bookingRQ);
                                Console.WriteLine("Booking Response:");
                                if (responseBooking != null)
                                {
                                    Console.WriteLine(JsonConvert.SerializeObject(responseBooking, Formatting.Indented, new JsonSerializerSettings()
                                    {
                                        DefaultValueHandling = DefaultValueHandling.Ignore
                                    }));
                                }
                                else
                                {
                                    Console.WriteLine("ResponseBooking Object Response is null");
                                }

                                if (responseBooking != null && responseBooking.error == null && responseBooking.booking != null)
                                {
                                    Console.WriteLine("Confirmation succedded. Canceling reservation with id " + responseBooking.booking.reference);
                                    param = new List <Tuple <string, string> >
                                    {
                                        new Tuple <string, string>("${bookingId}", responseBooking.booking.reference),
                                        //new Tuple<string, string>("${bookingId}", "1-3087550"),
                                        new Tuple <string, string>("${flag}", "C")
                                    };


                                    BookingCancellationRS bookingCancellationRS = client.Cancel(param);

                                    if (bookingCancellationRS != null)
                                    {
                                        Console.WriteLine("Id cancelled: " + responseBooking.booking.reference);
                                        Console.WriteLine(JsonConvert.SerializeObject(bookingCancellationRS, Formatting.Indented, new JsonSerializerSettings()
                                        {
                                            DefaultValueHandling = DefaultValueHandling.Ignore
                                        }));
                                        Console.ReadLine();

                                        Console.WriteLine("Getting detail after cancelation of id " + responseBooking.booking.reference);
                                        param = new List <Tuple <string, string> >
                                        {
                                            new Tuple <string, string>("${bookingId}", responseBooking.booking.reference)
                                        };
                                        BookingDetailRS bookingDetailRS = client.Detail(param);
                                        if (bookingDetailRS != null)
                                        {
                                            Console.WriteLine(JsonConvert.SerializeObject(bookingDetailRS, Formatting.Indented, new JsonSerializerSettings()
                                            {
                                                DefaultValueHandling = DefaultValueHandling.Ignore
                                            }));
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("No hotel available");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No availability!");
                }

                Console.WriteLine("Requesting booking list...");

                param = new List <Tuple <string, string> >
                {
                    new Tuple <string, string>("${start}", DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd")),
                    new Tuple <string, string>("${end}", DateTime.Now.ToString("yyyy-MM-dd")),
                    new Tuple <string, string>("${includeCancelled}", "true"),
                    new Tuple <string, string>("${filterType}", "CREATION"),
                    new Tuple <string, string>("${from}", "1"),
                    new Tuple <string, string>("${to}", "25"),
                };

                BookingListRS bookingListRS = client.List(param);
                if (bookingListRS != null)
                {
                    Console.WriteLine(JsonConvert.SerializeObject(bookingListRS, Formatting.Indented, new JsonSerializerSettings()
                    {
                        DefaultValueHandling = DefaultValueHandling.Ignore
                    }));
                    foreach (com.hotelbeds.distribution.hotel_api_model.auto.model.Booking booking in bookingListRS.bookings.bookings)
                    {
                        param = new List <Tuple <string, string> >
                        {
                            new Tuple <string, string>("${bookingId}", booking.reference)
                        };
                        BookingDetailRS bookingDetailRS = client.Detail(param);
                        if (bookingDetailRS != null)
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(bookingDetailRS, Formatting.Indented, new JsonSerializerSettings()
                            {
                                DefaultValueHandling = DefaultValueHandling.Ignore
                            }));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message + " " + e.StackTrace);
            }
            Console.ReadLine();
        }
Example #27
0
 public List <ClientAnalisedDTO> GetClientsList()
 {
     return(HotelApiClient.GetInstance().GetAnalisedClients());
 }
        //
        // GET: /BedBankBook/

        public ActionResult Index(FormCollection collection)
        {
            Hotel          hotelfiltered = new Hotel();
            HotelApiClient client        = new HotelApiClient();
            StatusRS       status        = client.status();
            List <Hotel>   hotels        = new List <Hotel>();

            if (status != null && status.error == null)
            {
                #region Commented
                //List<Tuple<string, string>> param;
                //Availability avail = new Availability();
                //avail.checkIn = Convert.ToDateTime(collection["checkIn"]);
                //avail.checkOut = Convert.ToDateTime(collection["checkOut"]);

                //var address = collection["add"];
                //ViewBag.checkIn = avail.checkIn;
                //ViewBag.checkOut = avail.checkOut;
                //avail.language = "CAS";
                //avail.shiftDays = 2;
                //AvailRoom room = new AvailRoom();
                //room.adults = Convert.ToInt32(collection["totalTravellers"]);
                //ViewBag.totalTravellers = room.adults;
                //room.children = 0;

                //room.details = new List<RoomDetail>();
                //room.adultOf(30);
                //avail.rooms.Add(room);
                //room = new AvailRoom();
                //room.children = 0;
                //room.details = new List<RoomDetail>();
                //room.adultOf(30);
                //avail.rooms.Add(room);
                //avail.payed = Availability.Pay.AT_HOTEL;


                #region Availability Request
                //AvailabilityRQ ar = new AvailabilityRQ();
                //ar.stay = new Stay(Convert.ToDateTime(collection["checkIn"]), Convert.ToDateTime(collection["checkOut"]), 0, true);

                //ar.occupancies = new List<Occupancy>();
                //ar.occupancies.Add(new Occupancy
                //{
                //    adults = Convert.ToInt32(collection["totalTravellers"]),
                //    //rooms = 1,
                //    rooms = 1,
                //    children = 0,
                //    paxes = new List<Pax>()
                //    {
                //        new Pax
                //        {
                //             age = 35,
                //             type = com.hotelbeds.distribution.hotel_api_model.auto.common.SimpleTypes.HotelbedsCustomerType.AD,
                //             name = "Munna",
                //             surname = "Singh"
                //        }
                //    }
                //});

                //ar.geolocation = new GeoLocation();
                //ar.geolocation.latitude = Convert.ToDouble(collection["LatOrg"]);
                //ar.geolocation.longitude = Convert.ToDouble(collection["LanOrg"]);

                //ViewBag.Lat = ar.geolocation.latitude;
                //ViewBag.Lan = ar.geolocation.longitude;
                //ar.geolocation.radius = 100;
                //ViewBag.radius = ar.geolocation.radius;

                //ar.geolocation.unit = com.hotelbeds.distribution.hotel_api_model.util.UnitMeasure.UnitMeasureType.km;

                #endregion Availability Request

                #endregion Commented

                #region Hotels Available
                //AvailabilityRS responseAvail = client.doAvailability(ar);
                //if (responseAvail != null && responseAvail.hotels != null && responseAvail.hotels.hotels != null && responseAvail.hotels.hotels.Count > 0)
                //{
                //    int hotelsAvailable = responseAvail.hotels.hotels.Count;
                //    hotels = responseAvail.hotels.hotels;
                //    int hotelcode = Convert.ToInt32(collection["hotelcode"]);
                //    ViewBag.HotelCode = hotelcode;
                //    ViewBag.TotalTravellers = Convert.ToInt32(collection["ddlTotalGuest"]);

                //    Hotel firstHotel = responseAvail.hotels.hotels.Where(ahotel => ahotel.code == hotelcode).FirstOrDefault();

                //    string rateKeySent = collection["rateKey"];
                //    string paymenttype = string.Empty;
                //    string rateKey = string.Empty;

                //    rateKey = rateKeySent;

                //    //paymenttype = firstHotel.rooms.SelectMany(y => y.rates)
                //    //    .Single(r => r.rateKey == rateKeySent).paymentType.ToString();

                //    foreach (var room1 in firstHotel.rooms)
                //    {
                //        foreach (var bbb in room1.rates)
                //        {
                //            if (rateKeySent == bbb.rateKey)
                //            {
                //                paymenttype = bbb.paymentType.ToString();
                //                continue;
                //            }
                //        }
                //    }



                #region Rate Key Available
                //if (!String.IsNullOrEmpty(rateKey))
                //{

                //    ConfirmRoom confirmRoom = new ConfirmRoom();
                //    confirmRoom.details = new List<RoomDetail>();
                //    confirmRoom.detailed(RoomDetail.GuestType.ADULT, 30, "Munna", "Singh", 1);
                //    string rateKeySent1 = collection["rateKey"];

                //    BookingCheck bookingCheck = new BookingCheck();
                //    bookingCheck.addRoom(rateKeySent1, confirmRoom);
                //    CheckRateRQ checkRateRQ = bookingCheck.toCheckRateRQ();

                //    //var vvv = client.doCheck(checkRateRQ

                //    #region if check rate is available
                //    if (checkRateRQ != null)
                //        {
                //            CheckRateRS responseRate = client.doCheck(checkRateRQ);
                //            if (responseRate.error != null)
                //                ViewBag.ErrorGot = responseRate.error.message;
                //            if (responseRate != null && responseRate.error == null)
                //            {
                //            BookingRQ bookingRQ = null;
                //            BookingRS responseBooking = null;
                //            if (responseRate.hotel.rooms[0].rates[0].paymentType.ToString() != "AT_WEB")
                //            {
                //                com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking booking = new com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking();
                //                booking.createHolder("Rosetta", "Pruebas");
                //                booking.clientReference = "SDK Test";
                //                booking.remark = "***SDK***TESTING";
                //                //NOTE: ONLY LIBERATE (PAY AT HOTEL MODEL) USES PAYMENT DATA NODES. FOR OTHER PRICING MODELS THESE NODES MUST NOT BE USED.
                //                booking.cardType = "VI";
                //                booking.cardNumber = "4444333322221111";
                //                booking.expiryDate = "0620";
                //                booking.cardCVC = "620";
                //                booking.email = "*****@*****.**";
                //                booking.phoneNumber = "654654654";
                //                booking.cardHolderName = "Munna Kumar Singh";

                //                booking.addRoom(rateKey, confirmRoom);

                //                #region BookingRQ
                //                bookingRQ = booking.toBookingRQ();

                //                responseBooking = client.confirm(bookingRQ);
                //            }

                //            if (bookingRQ == null)
                //            {
                //                if (paymenttype.ToString() == "AT_WEB")
                //                {
                //                    BookingRQ br = new BookingRQ();
                //                    br.rooms = new List<BookingRoom>();
                //                    br.rooms.Add(new BookingRoom
                //                    {
                //                        rateKey = rateKey,
                //                        paxes = new List<Pax>
                //                        {
                //                            Capacity = 1

                //                        }
                //                    });
                //                    br.remark = "***SDK***TESTING";
                //                    br.holder = new Holder();
                //                    br.holder.name = "Munna";
                //                    br.holder.surname = "Singh";

                //                    br.clientReference = "Client reference";

                //                    responseBooking = client.confirm(br);
                //                }
                //            }
                //            if (bookingRQ != null)
                //            {
                //                #region AT WEB
                //                if (paymenttype.ToString() == "AT_WEB")
                //                {
                //                    BookingRQ br = new BookingRQ();
                //                    br.rooms = new List<BookingRoom>();
                //                    br.rooms.Add(new BookingRoom
                //                    {
                //                        rateKey = rateKey,
                //                        paxes = new List<Pax>
                //                        {
                //                            Capacity = 1
                //                        }
                //                    });
                //                    br.remark = "***SDK***TESTING";
                //                    br.holder = new Holder();
                //                    br.holder.name = "Test";
                //                    br.holder.surname = "Surname";

                //                    br.clientReference = "Client reference";

                //                    responseBooking = client.confirm(br);

                //                }
                //                #endregion
                //                //"Booking Response"
                //                if (responseBooking != null)
                //                {
                //                    if (responseBooking.error != null)
                //                        ViewBag.ErrorGot = responseBooking.error.message;
                //                    else
                //                    {
                //                        ViewBag.BookingRef = responseBooking.booking.reference;
                //                    }
                //                    //if (responseBooking.booking.reference == null)

                //                }
                //                    //"Confirmation succedded. Canceling reservation with id "
                //                    #region Confirmation Succeeded
                //                    if (responseBooking != null && responseBooking.error == null && responseBooking.booking != null)
                //                    {
                //                        Console.WriteLine("Confirmation succedded. Canceling reservation with id " + responseBooking.booking.reference);
                //                        param = new List<Tuple<string, string>>
                //                        {
                //                            new Tuple<string, string>("${bookingId}", responseBooking.booking.reference),
                //                            //new Tuple<string, string>("${bookingId}", "1-3087550"),
                //                            new Tuple<string, string>("${flag}", "C")
                //                        };

                //                        BookingCancellationRS bookingCancellationRS = client.Cancel(param);

                //                        #region Cancel Booking
                //                        if (bookingCancellationRS != null)
                //                        {
                //                            //Console.WriteLine("Id cancelled: " + responseBooking.booking.reference);
                //                            ViewBag.BookCancelled = "cancelled" + responseBooking.booking.reference;

                //                        }
                //                        #endregion
                //                    }
                //                    #endregion
                //                }
                //                #endregion
                //            }
                //        }
                //        #endregion



                //}
                #endregion
                //}
                #endregion

                #region Rate Key Available
                //if (!String.IsNullOrEmpty(rateKey))
                //{
                string paymenttype = "";
                List <Tuple <string, string> > param;
                ConfirmRoom confirmRoom = new ConfirmRoom();
                confirmRoom.details = new List <RoomDetail>();
                confirmRoom.detailed(RoomDetail.GuestType.ADULT, 30, "Munna", "Singh", 1);
                string rateKeySent1 = collection["rateKey"];

                BookingCheck bookingCheck = new BookingCheck();
                bookingCheck.addRoom(rateKeySent1, confirmRoom);
                CheckRateRQ checkRateRQ = bookingCheck.toCheckRateRQ();

                #region if check rate is available
                if (checkRateRQ != null)
                {
                    CheckRateRS responseRate = client.doCheck(checkRateRQ);
                    if (responseRate.error != null)
                    {
                        ViewBag.ErrorGot = responseRate.error.message;
                    }
                    if (responseRate != null && responseRate.error == null)
                    {
                        BookingRQ bookingRQ       = null;
                        BookingRS responseBooking = null;
                        if (responseRate.hotel.rooms[0].rates[0].paymentType.ToString() != "AT_WEB")
                        {
                            com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking booking = new com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking();
                            booking.createHolder("Rosetta", "Pruebas");
                            booking.clientReference = "SDK Test";
                            booking.remark          = "***SDK***TESTING";
                            //NOTE: ONLY LIBERATE (PAY AT HOTEL MODEL) USES PAYMENT DATA NODES. FOR OTHER PRICING MODELS THESE NODES MUST NOT BE USED.
                            booking.cardType       = "VI";
                            booking.cardNumber     = "4444333322221111";
                            booking.expiryDate     = "0620";
                            booking.cardCVC        = "620";
                            booking.email          = "*****@*****.**";
                            booking.phoneNumber    = "654654654";
                            booking.cardHolderName = "Munna Kumar Singh";

                            booking.addRoom(rateKeySent1, confirmRoom);

                            #region BookingRQ
                            bookingRQ = booking.toBookingRQ();

                            responseBooking = client.confirm(bookingRQ);
                            var Request  = XMLSerializer.Serialize <BookingRQ>(bookingRQ);
                            var Response = XMLSerializer.Serialize <BookingRS>(responseBooking);
                        }

                        if (bookingRQ == null)
                        {
                            if (responseRate.hotel.rooms[0].rates[0].paymentType.ToString() == "AT_WEB")
                            {
                                BookingRQ br = new BookingRQ();
                                br.rooms = new List <BookingRoom>();
                                br.rooms.Add(new BookingRoom
                                {
                                    rateKey = rateKeySent1,
                                    paxes   = new List <Pax>
                                    {
                                        Capacity = 1
                                    }
                                });
                                br.remark         = "***SDK***TESTING";
                                br.holder         = new Holder();
                                br.holder.name    = "Munna";
                                br.holder.surname = "Singh";

                                br.clientReference = "Client reference";

                                responseBooking = client.confirm(br);
                                var Request  = XMLSerializer.Serialize <BookingRQ>(br);
                                var Response = XMLSerializer.Serialize <BookingRS>(responseBooking);
                            }
                        }
                        if (bookingRQ != null)
                        {
                            #region AT WEB
                            if (paymenttype.ToString() == "AT_WEB")
                            {
                                BookingRQ br = new BookingRQ();
                                br.rooms = new List <BookingRoom>();
                                br.rooms.Add(new BookingRoom
                                {
                                    rateKey = rateKeySent1,
                                    paxes   = new List <Pax>
                                    {
                                        Capacity = 1
                                    }
                                });
                                br.remark         = "***SDK***TESTING";
                                br.holder         = new Holder();
                                br.holder.name    = "Test";
                                br.holder.surname = "Surname";

                                br.clientReference = "Client reference";

                                responseBooking = client.confirm(br);
                            }
                            #endregion
                        }
                        #endregion

                        //"Booking Response"
                        if (responseBooking != null)
                        {
                            if (responseBooking.error != null)
                            {
                                ViewBag.ErrorGot = responseBooking.error.message;
                            }
                            else
                            {
                                ViewBag.BookingRef = responseBooking.booking.reference;
                            }
                            //if (responseBooking.booking.reference == null)
                        }
                        //"Confirmation succedded. Canceling reservation with id "
                        #region Confirmation Succeeded
                        if (responseBooking != null && responseBooking.error == null && responseBooking.booking != null)
                        {
                            Console.WriteLine("Confirmation succedded. Canceling reservation with id " + responseBooking.booking.reference);
                            param = new List <Tuple <string, string> >
                            {
                                new Tuple <string, string>("${bookingId}", responseBooking.booking.reference),
                                //new Tuple<string, string>("${bookingId}", "1-3087550"),
                                new Tuple <string, string>("${flag}", "C")
                            };

                            BookingCancellationRS bookingCancellationRS = client.Cancel(param);

                            #region Cancel Booking
                            if (bookingCancellationRS != null)
                            {
                                //Console.WriteLine("Id cancelled: " + responseBooking.booking.reference);
                                ViewBag.BookCancelled = "cancelled" + responseBooking.booking.reference;
                            }
                            #endregion
                        }
                        #endregion
                    }
                }
                #endregion

                //}
                #endregion
            }

            return(View());
        }
        //
        // GET: /result/
        public ActionResult Index()
        {
            try
            {
                HotelApiClient client = new HotelApiClient();
                StatusRS status = client.status();

                SearchCriteriaViewModel searchcriteria = (SearchCriteriaViewModel)Session["SearchCriteria"];

                List<Tuple<string, string>> param;

                Availability avail = new Availability();
                avail.checkIn = searchcriteria.CheckInDate;
                avail.checkOut = searchcriteria.CheckOutDate;
                avail.destination = searchcriteria.DestinationCode;
                avail.zone = searchcriteria.Zone;
                // avail.zone = 90;
                // avail.language = "CAS";
                if (searchcriteria.NumberOfRooms >= 1)
                {
                    AvailRoom room = new AvailRoom();
                    room.adults = searchcriteria.RoomOneAdults;
                    room.children = searchcriteria.RoomOneChildren + searchcriteria.RoomOneInfants;
                    room.details = new List<RoomDetail>();
                    for (int i = 0; i < searchcriteria.RoomOneAdults; i++)
                    { room.adultOf(30); }

                    for (int i = 0; i < searchcriteria.RoomOneChildren; i++)
                    { room.childOf(11); }

                    for (int i = 0; i < searchcriteria.RoomOneInfants; i++)
                    { room.childOf(2); }

                    //room.childOf(4);
                    avail.rooms.Add(room);
                }
                avail.payed = Availability.Pay.AT_WEB;
                //avail.ofTypes = new HashSet<hotel_api_model.auto.common.SimpleTypes.AccommodationType>();
                //avail.ofTypes.Add(hotel_api_model.auto.common.SimpleTypes.AccommodationType.HOTEL);
                //avail.ofTypes.Add(hotel_api_model.auto.common.SimpleTypes.AccommodationType.APARTMENT);

                avail.minCategory = searchcriteria.StarRatingSearch;
                //avail.limitHotelsTo = 10;
                //avail.numberOfTripAdvisorReviewsHigherThan = 2;
                //avail.tripAdvisorScoreHigherThan = 2

                //avail.matchingKeywords = new HashSet<int>();
                //avail.matchingKeywords.Add(34);
                //avail.matchingKeywords.Add(81);
                //avail.keywordsMatcher = Availability.Matcher.ALL;

                //avail.includeHotels = new List<int>();
                //avail.includeHotels.Add(111637);
                //avail.includeHotels.Add(2818);
                //avail.includeHotels.Add(138465);
                //avail.includeHotels.Add(164471);

                //avail.excludeHotels = new List<int>();
                //avail.excludeHotels.Add(187013);
                //avail.excludeHotels.Add(188330);

                //avail.useGiataCodes = false;
                //avail.limitHotelsTo = 250;
                //avail.limitRoomsPerHotelTo = 5;
                //avail.limitRatesPerRoomTo = 5;
                //avail.ratesHigherThan = 50;
                //avail.ratesLowerThan = 350;

                //avail.hbScoreHigherThan = 3;
                //avail.hbScoreLowerThan = 5;
                //avail.numberOfHBReviewsHigherThan = 50;

                //avail.tripAdvisorScoreHigherThan = 1;
                //avail.tripAdvisorScoreLowerThan = 4;
                //avail.numberOfHBReviewsHigherThan = 50;

                //avail.withinThis = new Availability.Circle() { latitude = 2.646633999999949, longitude = 39.57119, radiusInKilometers = 50 };
                //avail.withinThis = new Availability.Square() { northEastLatitude = 45.37680856570233, northEastLongitude = -2.021484375, southWestLatitude = 38.548165423046584, southWestLongitude = 8.658203125 };

                //avail.includeBoards = new List<string>();
                //avail.includeBoards.Add("R0-E10");
                //avail.includeBoards.Add("BB-E10");
                //avail.excludeBoards = new List<string>();
                //avail.excludeBoards.Add("RO");

                //avail.includeRoomCodes = new List<string>();
                //avail.includeRoomCodes.Add("DBL.ST");
                //avail.includeRoomCodes.Add("DBL.SU");
                ////avail.includeRoomCodes.AddRange(new string[]{ "DBL.ST", "DBL.SU" });
                //avail.excludeRoomCodes = new List<string>();
                //avail.excludeRoomCodes.Add("TPL.ST");

                AvailabilityRQ availabilityRQ = avail.toAvailabilityRQ();
                if (availabilityRQ == null)
                    throw new Exception("Availability RQ can't be null", new ArgumentNullException());
                Stopwatch sw = new Stopwatch();
                sw.Start();
                AvailabilityRS responseAvail = client.doAvailability(availabilityRQ);
                sw.Stop();
                ViewBag.TimeTaken = sw.Elapsed.Seconds;

                //  request.PathToSaveXml = Server.MapPath("~");

                if (responseAvail != null && responseAvail.hotels != null && responseAvail.hotels.hotels != null && responseAvail.hotels.hotels.Count > 0)
                {

                    Session["ResultedHotels"] = responseAvail.hotels;

                }

                return View(responseAvail);
            }
            catch (Exception exp)
            { return Content(exp.Message); }
        }
Example #30
0
 public ClientDTO GetClient(string clientTel)
 {
     return(HotelApiClient.GetInstance().GetClient(clientTel));
 }
Example #31
0
        static void Main(string[] args)
        {
            try
            {

                HotelApiClient client = new HotelApiClient();
                StatusRS status = client.status();

                if (status != null && status.error == null)
                    Console.WriteLine("StatusRS: " + status.status);
                else if (status != null && status.error != null)
                {
                    Console.WriteLine("StatusRS: " + status.status + " " + status.error.code + ": " + status.error.message);
                    return;
                }
                else if (status == null)
                {
                    Console.WriteLine("StatusRS: Is not available.");
                    return;
                }

                List<Tuple<string, string>> param;

                Availability avail = new Availability();
                avail.checkIn = DateTime.Now.AddDays(10);
                avail.checkOut = DateTime.Now.AddDays(13);
                avail.destination = "PMI";
                avail.zone = 90;
                avail.language = "CAS";
                AvailRoom room = new AvailRoom();
                room.adults = 2;
                room.children = 0;
                room.details = new List<RoomDetail>();
                room.adultOf(30);
                room.adultOf(30);
                //room.childOf(4);
                avail.rooms.Add(room);
                avail.payed = Availability.Pay.AT_HOTEL;
                //avail.ofTypes = new HashSet<hotel_api_model.auto.common.SimpleTypes.AccommodationType>();
                //avail.ofTypes.Add(hotel_api_model.auto.common.SimpleTypes.AccommodationType.HOTEL);
                //avail.ofTypes.Add(hotel_api_model.auto.common.SimpleTypes.AccommodationType.APARTMENT);

                //avail.minCategory = 4;
                //avail.limitHotelsTo = 10;
                //avail.numberOfTripAdvisorReviewsHigherThan = 2;
                //avail.tripAdvisorScoreHigherThan = 2

                //avail.matchingKeywords = new HashSet<int>();
                //avail.matchingKeywords.Add(34);
                //avail.matchingKeywords.Add(81);
                //avail.keywordsMatcher = Availability.Matcher.ALL;

                //avail.includeHotels = new List<int>();
                //avail.includeHotels.Add(111637);
                //avail.includeHotels.Add(2818);
                //avail.includeHotels.Add(138465);
                //avail.includeHotels.Add(164471);

                //avail.excludeHotels = new List<int>();
                //avail.excludeHotels.Add(187013);
                //avail.excludeHotels.Add(188330);

                //avail.useGiataCodes = false;
                //avail.limitHotelsTo = 250;
                //avail.limitRoomsPerHotelTo = 5;
                //avail.limitRatesPerRoomTo = 5;
                //avail.ratesHigherThan = 50;
                //avail.ratesLowerThan = 350;

                //avail.hbScoreHigherThan = 3;
                //avail.hbScoreLowerThan = 5;
                //avail.numberOfHBReviewsHigherThan = 50;

                //avail.tripAdvisorScoreHigherThan = 1;
                //avail.tripAdvisorScoreLowerThan = 4;
                //avail.numberOfHBReviewsHigherThan = 50;

                //avail.withinThis = new Availability.Circle() { latitude = 2.646633999999949, longitude = 39.57119, radiusInKilometers = 50 };
                //avail.withinThis = new Availability.Square() { northEastLatitude = 45.37680856570233, northEastLongitude = -2.021484375, southWestLatitude = 38.548165423046584, southWestLongitude = 8.658203125 };

                //avail.includeBoards = new List<string>();
                //avail.includeBoards.Add("R0-E10");
                //avail.includeBoards.Add("BB-E10");
                //avail.excludeBoards = new List<string>();
                //avail.excludeBoards.Add("RO");

                //avail.includeRoomCodes = new List<string>();
                //avail.includeRoomCodes.Add("DBL.ST");
                //avail.includeRoomCodes.Add("DBL.SU");
                ////avail.includeRoomCodes.AddRange(new string[]{ "DBL.ST", "DBL.SU" });
                //avail.excludeRoomCodes = new List<string>();
                //avail.excludeRoomCodes.Add("TPL.ST");

                AvailabilityRQ availabilityRQ = avail.toAvailabilityRQ();
                if (availabilityRQ == null)
                    throw new Exception("Availability RQ can't be null", new ArgumentNullException());

                AvailabilityRS responseAvail = client.doAvailability(availabilityRQ);

                if (responseAvail != null && responseAvail.hotels != null && responseAvail.hotels.hotels != null && responseAvail.hotels.hotels.Count > 0)
                {
                    Console.WriteLine(string.Format("Availability answered with {0} hotels!", responseAvail.hotels.hotels.Count));
                    Console.WriteLine(JsonConvert.SerializeObject(responseAvail, Formatting.Indented, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore }));

                    //  ***********************************
                    //  Try to check reservation with rate
                    //  ***********************************

                    Hotel firstHotel = responseAvail.hotels.hotels.First();
                    string rateKey = string.Empty;

                    for (int r = 0; r < firstHotel.rooms.Count && String.IsNullOrEmpty(rateKey); r++)
                    {
                        for (int rk = 0; firstHotel.rooms[r].rates != null && rk < firstHotel.rooms[r].rates.Count && String.IsNullOrEmpty(rateKey); rk++)
                        {
                            rateKey = firstHotel.rooms[r].rates[rk].rateKey;
                        }
                    }

                    if (String.IsNullOrEmpty(rateKey))
                    {
                        Console.WriteLine("No hotel available");
                        return;
                    }

                    Console.WriteLine("Checking reservation with rate " + rateKey);

                    ConfirmRoom confirmRoom = new ConfirmRoom();
                    confirmRoom.details = new List<RoomDetail>();
                    confirmRoom.detailed(RoomDetail.GuestType.ADULT, 30, "NombrePasajero1","ApellidoPasajero1", 1);
                    confirmRoom.detailed(RoomDetail.GuestType.ADULT, 30, "NombrePasajero2", "ApellidoPasajero2", 1);

                    BookingCheck bookingCheck = new BookingCheck();
                    bookingCheck.addRoom(rateKey, confirmRoom);
                    CheckRateRQ checkRateRQ = bookingCheck.toCheckRateRQ();

                    if (checkRateRQ != null)
                    {
                        CheckRateRS responseRate = client.doCheck(checkRateRQ);
                        if (responseRate != null && responseRate.error == null)
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(responseRate, Formatting.Indented, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore }));

                            com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking booking = new com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking();
                            booking.createHolder("Rosetta", "Pruebas");
                            booking.clientReference = "SDK Test";
                            booking.remark = "***SDK***TESTING";

                            //NOTE: ONLY LIBERATE (PAY AT HOTEL MODEL) USES PAYMENT DATA NODES. FOR OTHER PRICING MODELS THESE NODES MUST NOT BE USED.
                            booking.cardType = "VI";
                            booking.cardNumber = "4444333322221111";
                            booking.expiryDate = "0620";
                            booking.cardCVC = "0620";
                            booking.email = "*****@*****.**";
                            booking.phoneNumber = "654654654";
                            booking.cardHolderName = "AUTHORISED";

                            booking.addRoom(rateKey, confirmRoom);
                            BookingRQ bookingRQ = booking.toBookingRQ();
                            if (bookingRQ != null)
                            {
                                BookingRS responseBooking = client.confirm(bookingRQ);
                                if (responseBooking != null)
                                    Console.WriteLine(JsonConvert.SerializeObject(responseBooking, Formatting.Indented, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore }));
                                else
                                    Console.WriteLine("ResponseBooking Object Response is null");

                                if (responseBooking != null && responseBooking.error == null && responseBooking.booking != null)
                                {
                                    Console.WriteLine("Confirmation succedded. Canceling reservation with id " + responseBooking.booking.reference);
                                    param = new List<Tuple<string, string>>
                                    {
                                        //new Tuple<string, string>("${bookingId}", responseBooking.booking.reference),
                                        new Tuple<string, string>("${bookingId}", "1-3087550"),
                                        new Tuple<string, string>("${flag}", "C")
                                    };

                                    Console.WriteLine("Getting detail after cancelation of id " + responseBooking.booking.reference);

                                    BookingCancellationRS bookingCancellationRS = client.Cancel(param);

                                    if (bookingCancellationRS != null)
                                    {
                                        Console.WriteLine("Id cancelled: " + responseBooking.booking.reference);
                                        Console.WriteLine(JsonConvert.SerializeObject(bookingCancellationRS, Formatting.Indented, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore }));
                                        param = new List<Tuple<string, string>>
                                        {
                                            new Tuple<string, string>("${bookingId}", responseBooking.booking.reference)
                                        };
                                        BookingDetailRS bookingDetailRS = client.Detail(param);
                                        if (bookingDetailRS != null)
                                            Console.WriteLine(JsonConvert.SerializeObject(bookingDetailRS, Formatting.Indented, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore }));
                                    }
                                }
                            }
                        }
                        else
                            Console.WriteLine("No hotel available");
                    }
                }
                else
                    Console.WriteLine("No availability!");

                Console.WriteLine("Requesting booking list...");

                param = new List<Tuple<string, string>>
                {
                    new Tuple<string, string>("${start}", DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd")),
                    new Tuple<string, string>("${end}", DateTime.Now.ToString("yyyy-MM-dd")),
                    new Tuple<string, string>("${includeCancelled}", "true"),
                    new Tuple<string, string>("${filterType}", "CREATION"),
                    new Tuple<string, string>("${from}", "1"),
                    new Tuple<string, string>("${to}", "25"),
                };

                BookingListRS bookingListRS = client.List(param);
                if (bookingListRS != null)
                {
                    Console.WriteLine(JsonConvert.SerializeObject(bookingListRS, Formatting.Indented, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore }));
                    foreach (com.hotelbeds.distribution.hotel_api_model.auto.model.Booking booking in bookingListRS.bookings.bookings)
                    {
                        param = new List<Tuple<string, string>>
                        {
                            new Tuple<string, string>("${bookingId}", booking.reference)
                        };
                        BookingDetailRS bookingDetailRS = client.Detail(param);
                        if (bookingDetailRS != null)
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(bookingDetailRS, Formatting.Indented, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore }));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message + " " + e.StackTrace);
            }
        }
 private void ReinitItems()
 {
     Stats = new ObservableCollection <CleaningStatsDTO>(HotelApiClient.GetInstance().GetCleaningsStats(SelectedDate));
 }
        //
        // GET: /BedBankBook/
        public ActionResult Index(FormCollection collection)
        {
            Hotel hotelfiltered = new Hotel();
            HotelApiClient client = new HotelApiClient();
            StatusRS status = client.status();
            List<Hotel> hotels = new List<Hotel>();
            if (status != null && status.error == null)
            {
                #region Commented
                //List<Tuple<string, string>> param;
                //Availability avail = new Availability();
                //avail.checkIn = Convert.ToDateTime(collection["checkIn"]);
                //avail.checkOut = Convert.ToDateTime(collection["checkOut"]);

                //var address = collection["add"];
                //ViewBag.checkIn = avail.checkIn;
                //ViewBag.checkOut = avail.checkOut;
                //avail.language = "CAS";
                //avail.shiftDays = 2;
                //AvailRoom room = new AvailRoom();
                //room.adults = Convert.ToInt32(collection["totalTravellers"]);
                //ViewBag.totalTravellers = room.adults;
                //room.children = 0;

                //room.details = new List<RoomDetail>();
                //room.adultOf(30);
                //avail.rooms.Add(room);
                //room = new AvailRoom();
                //room.children = 0;
                //room.details = new List<RoomDetail>();
                //room.adultOf(30);
                //avail.rooms.Add(room);
                //avail.payed = Availability.Pay.AT_HOTEL;

                #region Availability Request
                //AvailabilityRQ ar = new AvailabilityRQ();
                //ar.stay = new Stay(Convert.ToDateTime(collection["checkIn"]), Convert.ToDateTime(collection["checkOut"]), 0, true);

                //ar.occupancies = new List<Occupancy>();
                //ar.occupancies.Add(new Occupancy
                //{
                //    adults = Convert.ToInt32(collection["totalTravellers"]),
                //    //rooms = 1,
                //    rooms = 1,
                //    children = 0,
                //    paxes = new List<Pax>()
                //    {
                //        new Pax
                //        {
                //             age = 35,
                //             type = com.hotelbeds.distribution.hotel_api_model.auto.common.SimpleTypes.HotelbedsCustomerType.AD,
                //             name = "Munna",
                //             surname = "Singh"
                //        }
                //    }
                //});

                //ar.geolocation = new GeoLocation();
                //ar.geolocation.latitude = Convert.ToDouble(collection["LatOrg"]);
                //ar.geolocation.longitude = Convert.ToDouble(collection["LanOrg"]);

                //ViewBag.Lat = ar.geolocation.latitude;
                //ViewBag.Lan = ar.geolocation.longitude;
                //ar.geolocation.radius = 100;
                //ViewBag.radius = ar.geolocation.radius;

                //ar.geolocation.unit = com.hotelbeds.distribution.hotel_api_model.util.UnitMeasure.UnitMeasureType.km;

                #endregion Availability Request

                #endregion Commented

                #region Hotels Available
                //AvailabilityRS responseAvail = client.doAvailability(ar);
                //if (responseAvail != null && responseAvail.hotels != null && responseAvail.hotels.hotels != null && responseAvail.hotels.hotels.Count > 0)
                //{
                //    int hotelsAvailable = responseAvail.hotels.hotels.Count;
                //    hotels = responseAvail.hotels.hotels;
                //    int hotelcode = Convert.ToInt32(collection["hotelcode"]);
                //    ViewBag.HotelCode = hotelcode;
                //    ViewBag.TotalTravellers = Convert.ToInt32(collection["ddlTotalGuest"]);

                //    Hotel firstHotel = responseAvail.hotels.hotels.Where(ahotel => ahotel.code == hotelcode).FirstOrDefault();

                //    string rateKeySent = collection["rateKey"];
                //    string paymenttype = string.Empty;
                //    string rateKey = string.Empty;

                //    rateKey = rateKeySent;

                //    //paymenttype = firstHotel.rooms.SelectMany(y => y.rates)
                //    //    .Single(r => r.rateKey == rateKeySent).paymentType.ToString();

                //    foreach (var room1 in firstHotel.rooms)
                //    {
                //        foreach (var bbb in room1.rates)
                //        {
                //            if (rateKeySent == bbb.rateKey)
                //            {
                //                paymenttype = bbb.paymentType.ToString();
                //                continue;
                //            }
                //        }
                //    }

                #region Rate Key Available
                //if (!String.IsNullOrEmpty(rateKey))
                //{

                //    ConfirmRoom confirmRoom = new ConfirmRoom();
                //    confirmRoom.details = new List<RoomDetail>();
                //    confirmRoom.detailed(RoomDetail.GuestType.ADULT, 30, "Munna", "Singh", 1);
                //    string rateKeySent1 = collection["rateKey"];

                //    BookingCheck bookingCheck = new BookingCheck();
                //    bookingCheck.addRoom(rateKeySent1, confirmRoom);
                //    CheckRateRQ checkRateRQ = bookingCheck.toCheckRateRQ();

                //    //var vvv = client.doCheck(checkRateRQ

                //    #region if check rate is available
                //    if (checkRateRQ != null)
                //        {
                //            CheckRateRS responseRate = client.doCheck(checkRateRQ);
                //            if (responseRate.error != null)
                //                ViewBag.ErrorGot = responseRate.error.message;
                //            if (responseRate != null && responseRate.error == null)
                //            {
                //            BookingRQ bookingRQ = null;
                //            BookingRS responseBooking = null;
                //            if (responseRate.hotel.rooms[0].rates[0].paymentType.ToString() != "AT_WEB")
                //            {
                //                com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking booking = new com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking();
                //                booking.createHolder("Rosetta", "Pruebas");
                //                booking.clientReference = "SDK Test";
                //                booking.remark = "***SDK***TESTING";
                //                //NOTE: ONLY LIBERATE (PAY AT HOTEL MODEL) USES PAYMENT DATA NODES. FOR OTHER PRICING MODELS THESE NODES MUST NOT BE USED.
                //                booking.cardType = "VI";
                //                booking.cardNumber = "4444333322221111";
                //                booking.expiryDate = "0620";
                //                booking.cardCVC = "620";
                //                booking.email = "*****@*****.**";
                //                booking.phoneNumber = "654654654";
                //                booking.cardHolderName = "Munna Kumar Singh";

                //                booking.addRoom(rateKey, confirmRoom);

                //                #region BookingRQ
                //                bookingRQ = booking.toBookingRQ();

                //                responseBooking = client.confirm(bookingRQ);
                //            }

                //            if (bookingRQ == null)
                //            {
                //                if (paymenttype.ToString() == "AT_WEB")
                //                {
                //                    BookingRQ br = new BookingRQ();
                //                    br.rooms = new List<BookingRoom>();
                //                    br.rooms.Add(new BookingRoom
                //                    {
                //                        rateKey = rateKey,
                //                        paxes = new List<Pax>
                //                        {
                //                            Capacity = 1

                //                        }
                //                    });
                //                    br.remark = "***SDK***TESTING";
                //                    br.holder = new Holder();
                //                    br.holder.name = "Munna";
                //                    br.holder.surname = "Singh";

                //                    br.clientReference = "Client reference";

                //                    responseBooking = client.confirm(br);
                //                }
                //            }
                //            if (bookingRQ != null)
                //            {
                //                #region AT WEB
                //                if (paymenttype.ToString() == "AT_WEB")
                //                {
                //                    BookingRQ br = new BookingRQ();
                //                    br.rooms = new List<BookingRoom>();
                //                    br.rooms.Add(new BookingRoom
                //                    {
                //                        rateKey = rateKey,
                //                        paxes = new List<Pax>
                //                        {
                //                            Capacity = 1
                //                        }
                //                    });
                //                    br.remark = "***SDK***TESTING";
                //                    br.holder = new Holder();
                //                    br.holder.name = "Test";
                //                    br.holder.surname = "Surname";

                //                    br.clientReference = "Client reference";

                //                    responseBooking = client.confirm(br);

                //                }
                //                #endregion
                //                //"Booking Response"
                //                if (responseBooking != null)
                //                {
                //                    if (responseBooking.error != null)
                //                        ViewBag.ErrorGot = responseBooking.error.message;
                //                    else
                //                    {
                //                        ViewBag.BookingRef = responseBooking.booking.reference;
                //                    }
                //                    //if (responseBooking.booking.reference == null)

                //                }
                //                    //"Confirmation succedded. Canceling reservation with id "
                //                    #region Confirmation Succeeded
                //                    if (responseBooking != null && responseBooking.error == null && responseBooking.booking != null)
                //                    {
                //                        Console.WriteLine("Confirmation succedded. Canceling reservation with id " + responseBooking.booking.reference);
                //                        param = new List<Tuple<string, string>>
                //                        {
                //                            new Tuple<string, string>("${bookingId}", responseBooking.booking.reference),
                //                            //new Tuple<string, string>("${bookingId}", "1-3087550"),
                //                            new Tuple<string, string>("${flag}", "C")
                //                        };

                //                        BookingCancellationRS bookingCancellationRS = client.Cancel(param);

                //                        #region Cancel Booking
                //                        if (bookingCancellationRS != null)
                //                        {
                //                            //Console.WriteLine("Id cancelled: " + responseBooking.booking.reference);
                //                            ViewBag.BookCancelled = "cancelled" + responseBooking.booking.reference;

                //                        }
                //                        #endregion
                //                    }
                //                    #endregion
                //                }
                //                #endregion
                //            }
                //        }
                //        #endregion

                //}
                #endregion
                //}
                #endregion

                #region Rate Key Available
                //if (!String.IsNullOrEmpty(rateKey))
                //{
                string paymenttype = "";
                List<Tuple<string, string>> param;
                ConfirmRoom confirmRoom = new ConfirmRoom();
                confirmRoom.details = new List<RoomDetail>();
                confirmRoom.detailed(RoomDetail.GuestType.ADULT, 30, "Munna", "Singh", 1);
                string rateKeySent1 = collection["rateKey"];

                BookingCheck bookingCheck = new BookingCheck();
                bookingCheck.addRoom(rateKeySent1, confirmRoom);
                CheckRateRQ checkRateRQ = bookingCheck.toCheckRateRQ();

                #region if check rate is available
                if (checkRateRQ != null)
                {
                    CheckRateRS responseRate = client.doCheck(checkRateRQ);
                    if (responseRate.error != null)
                        ViewBag.ErrorGot = responseRate.error.message;
                    if (responseRate != null && responseRate.error == null)
                    {
                        BookingRQ bookingRQ = null;
                        BookingRS responseBooking = null;
                        if (responseRate.hotel.rooms[0].rates[0].paymentType.ToString() != "AT_WEB")
                        {
                            com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking booking = new com.hotelbeds.distribution.hotel_api_sdk.helpers.Booking();
                            booking.createHolder("Rosetta", "Pruebas");
                            booking.clientReference = "SDK Test";
                            booking.remark = "***SDK***TESTING";
                            //NOTE: ONLY LIBERATE (PAY AT HOTEL MODEL) USES PAYMENT DATA NODES. FOR OTHER PRICING MODELS THESE NODES MUST NOT BE USED.
                            booking.cardType = "VI";
                            booking.cardNumber = "4444333322221111";
                            booking.expiryDate = "0620";
                            booking.cardCVC = "620";
                            booking.email = "*****@*****.**";
                            booking.phoneNumber = "654654654";
                            booking.cardHolderName = "Munna Kumar Singh";

                            booking.addRoom(rateKeySent1, confirmRoom);

                            #region BookingRQ
                            bookingRQ = booking.toBookingRQ();

                            responseBooking = client.confirm(bookingRQ);
                            var Request = XMLSerializer.Serialize<BookingRQ>(bookingRQ);
                            var Response = XMLSerializer.Serialize<BookingRS>(responseBooking);
                        }

                        if (bookingRQ == null)
                        {
                            if (responseRate.hotel.rooms[0].rates[0].paymentType.ToString() == "AT_WEB")
                            {
                                BookingRQ br = new BookingRQ();
                                br.rooms = new List<BookingRoom>();
                                br.rooms.Add(new BookingRoom
                                {
                                    rateKey = rateKeySent1,
                                    paxes = new List<Pax>
                                    {
                                        Capacity = 1

                                    }
                                });
                                br.remark = "***SDK***TESTING";
                                br.holder = new Holder();
                                br.holder.name = "Munna";
                                br.holder.surname = "Singh";

                                br.clientReference = "Client reference";

                                responseBooking = client.confirm(br);
                                var Request = XMLSerializer.Serialize<BookingRQ>(br);
                                var Response = XMLSerializer.Serialize<BookingRS>(responseBooking);

                            }
                        }
                        if (bookingRQ != null)
                        {
                            #region AT WEB
                            if (paymenttype.ToString() == "AT_WEB")
                            {
                                BookingRQ br = new BookingRQ();
                                br.rooms = new List<BookingRoom>();
                                br.rooms.Add(new BookingRoom
                                {
                                    rateKey = rateKeySent1,
                                    paxes = new List<Pax>
                                    {
                                        Capacity = 1
                                    }
                                });
                                br.remark = "***SDK***TESTING";
                                br.holder = new Holder();
                                br.holder.name = "Test";
                                br.holder.surname = "Surname";

                                br.clientReference = "Client reference";

                                responseBooking = client.confirm(br);

                            }
                            #endregion

                        }
                        #endregion

                        //"Booking Response"
                        if (responseBooking != null)
                        {
                            if (responseBooking.error != null)
                                ViewBag.ErrorGot = responseBooking.error.message;
                            else
                            {
                                ViewBag.BookingRef = responseBooking.booking.reference;
                            }
                            //if (responseBooking.booking.reference == null)

                        }
                        //"Confirmation succedded. Canceling reservation with id "
                        #region Confirmation Succeeded
                        if (responseBooking != null && responseBooking.error == null && responseBooking.booking != null)
                        {
                            Console.WriteLine("Confirmation succedded. Canceling reservation with id " + responseBooking.booking.reference);
                            param = new List<Tuple<string, string>>
                                            {
                                                new Tuple<string, string>("${bookingId}", responseBooking.booking.reference),
                                                //new Tuple<string, string>("${bookingId}", "1-3087550"),
                                                new Tuple<string, string>("${flag}", "C")
                                            };

                            BookingCancellationRS bookingCancellationRS = client.Cancel(param);

                            #region Cancel Booking
                            if (bookingCancellationRS != null)
                            {
                                //Console.WriteLine("Id cancelled: " + responseBooking.booking.reference);
                                ViewBag.BookCancelled = "cancelled" + responseBooking.booking.reference;

                            }
                            #endregion
                        }
                        #endregion
                    }
                }
                #endregion

                //}
                #endregion
            }

            return View();
        }