com.hotelbeds.distribution.hotel_api_model.auto.messages.BookingRQ.Validate C# (CSharp) Method

Validate() public method

public Validate ( ) : void
return void
        public void Validate()
        {
            if(holder == null || String.IsNullOrEmpty(holder.name) || String.IsNullOrEmpty(holder.surname))
                throw new ArgumentException("Holder object can't be null");

            if(rooms == null || rooms.Count == 0)
                throw new ArgumentException("Rooms list can't be null");

            for(int r = 0; r < rooms.Count; r++)
            {
                if(String.IsNullOrEmpty(rooms[r].rateKey))
                    throw new ArgumentException("RateKey Room can't be null");

                if(rooms[r].paxes == null || rooms[r].paxes.Count == 0)
                    throw new ArgumentException("Paxes list can't be null");

                for(int p = 0; p < rooms[r].paxes.Count; p++)
                {
                    if ( rooms[r].paxes[p].type == null )
                        throw new ArgumentException("Paxes Type can't be null");

                    if (String.IsNullOrEmpty(rooms[r].paxes[p].name))
                        throw new ArgumentException("Paxes name can't be null");

                    if (String.IsNullOrEmpty(rooms[r].paxes[p].surname))
                        throw new ArgumentException("Paxes surname can't be null");

                    if (!rooms[r].paxes[p].age.HasValue)
                        throw new ArgumentException("Paxes age can't be null");

                    if (!rooms[r].paxes[p].roomId.HasValue)
                        throw new ArgumentException("RoomId can't be null");
                }
            }

            if(String.IsNullOrEmpty(clientReference))
                throw new ArgumentException("Client Reference can't be null");

            if(paymentData != null)
            {
                if( paymentData.paymentCard == null )
                    throw new ArgumentException("PaymentCard can't be null");

                if (String.IsNullOrEmpty(paymentData.paymentCard.cardType))
                    throw new ArgumentException("CardType can't be null");

                if (String.IsNullOrEmpty(paymentData.paymentCard.cardNumber))
                    throw new ArgumentException("CardNumber can't be null");

                if(String.IsNullOrEmpty(paymentData.paymentCard.expiryDate))
                    throw new ArgumentException("ExpiryDate can't be null");

                if(String.IsNullOrEmpty(paymentData.paymentCard.cardCVC))
                    throw new ArgumentException("CardCVC can't be null");

                if(paymentData.contactData == null)
                    throw new ArgumentException("ContactData can't be null");

                if (String.IsNullOrEmpty(paymentData.contactData.email))
                    throw new ArgumentException("Email can't be null or empty");

                if (String.IsNullOrEmpty(paymentData.contactData.phoneNumber))
                    throw new ArgumentException("PhoneNumber can't be null or empty");
            }
        }

Usage Example

        public BookingRQ toBookingRQ()
        {
            BookingRQ bookingRQ = new BookingRQ();
            bookingRQ.holder = this.holder;
            bookingRQ.clientReference = this.clientReference;
            bookingRQ.remark = this.remark;
            if ( !String.IsNullOrEmpty(cardType) && !String.IsNullOrEmpty(cardNumber) && !String.IsNullOrEmpty(cardHolderName) && !String.IsNullOrEmpty(expiryDate) && cardCVC != null ||
                !String.IsNullOrEmpty(email) && !String.IsNullOrEmpty(phoneNumber))
            {
                PaymentData paymentData = new PaymentData();
                if ( !String.IsNullOrEmpty(cardType) && !String.IsNullOrEmpty(cardNumber) && !String.IsNullOrEmpty(cardHolderName) && !String.IsNullOrEmpty(expiryDate) && !String.IsNullOrEmpty(cardCVC))
                    paymentData.paymentCard = new PaymentCard() { cardType = cardType, cardNumber = cardNumber, cardHolderName = cardHolderName, expiryDate = expiryDate, cardCVC = cardCVC  };

                if (!String.IsNullOrEmpty(email) && !String.IsNullOrEmpty(phoneNumber))
                    paymentData.contactData = new PaymentContactData() { email = email, phoneNumber = phoneNumber };

                bookingRQ.paymentData = paymentData;
            }

            for(int i = 0; i < rooms.Count; i++)
            {
                BookingRoom room = new BookingRoom();
                room.rateKey = rooms[i].rateKey;
                room.paxes = new List<Pax>();
                for(int p = 0; p < rooms[i].details.Count; p++)
                {
                    Pax pax = new Pax();
                    pax.type = (rooms[i].details[p].getType() == RoomDetail.GuestType.ADULT) ? SimpleTypes.HotelbedsCustomerType.AD : SimpleTypes.HotelbedsCustomerType.CH;
                    pax.age = rooms[i].details[p].getAge();
                    pax.name = rooms[i].details[p].getName();
                    pax.surname = rooms[i].details[p].getSurname();
                    pax.roomId = rooms[i].details[p].getRoomId();
                    room.paxes.Add(pax);
                }
                bookingRQ.rooms.Add(room);
            }

            bookingRQ.Validate();

            return bookingRQ;
        }