public Credential GetCredential(string userKey)
            {
                var credential = new CheckArgentina.Models.Credential();

                using (var dc = new TurismoDataContext())
                {
                    Guid idUsuario;

                    if (Guid.TryParse(userKey, out idUsuario))
                    {
                        var users = dc.Usuarios.Where(u => u.IDUSUARIO == idUsuario);

                        if (users.Count() == 1)
                        {
                            credential.Username = users.First().NOMBREUSUARIO;
                            credential.Password = users.First().CLAVE;
                            credential.Language = "es";
                        }
                        else
                        {
                            credential.Username = string.Empty;
                            credential.Password = string.Empty;
                            credential.Language = string.Empty;
                        }
                    }
                }

                return(credential);
            }
            public DestinationListModel SearchDestination(string destinationName, CheckArgentina.Models.Credential userCredential, DestinationModel parent = null)
            {
                SessionData.SearchType = SearchType.International;

                var results      = new DestinationListModel();
                var destinations = new List <DestinationModel>();

                var rqlocations = new WSHCEV_main.DestinationListRQ();
                var x           = new System.Xml.Serialization.XmlSerializer(rqlocations.GetType());
                var sw          = new System.IO.StringWriter();
                var xw          = new System.Xml.XmlTextWriter(sw);
                var wsRnd       = new ServicioPruebaHeredado();

                try
                {
                    if (parent != null || (parent == null && (CacheData.Countries == null || CacheData.CountryListLastModification < DateTime.Today)))
                    {
                        rqlocations.Source = new WSHCEV_main.Source();
                        rqlocations.Source.PricingSurferConfiguration = new WSHCEV_main.PricingSurferConfiguration();
                        rqlocations.Source.PricingSurferConfiguration.PreferedLanguage = new WSHCEV_main.PreferedLanguage();
                        rqlocations.Source.PricingSurferConfiguration.PreferedCurrency = new WSHCEV_main.PreferedCurrency();
                        rqlocations.Source.PricingSurferConfiguration.ResponseSet      = new WSHCEV_main.ResponseSet();
                        rqlocations.Source.PricingSurferConfiguration.ContractId       = 10273; // 10857;
                        rqlocations.Source.PricingSurferConfiguration.PreferedLanguage.LanguageCode = "es";
                        rqlocations.Source.PricingSurferConfiguration.PreferedCurrency.CurrencyCode = "USD";
                        rqlocations.Source.PricingSurferConfiguration.ResponseSet.FirstItem         = 1;
                        rqlocations.Source.PricingSurferConfiguration.ResponseSet.ItemsPerPage      = 1500;

                        rqlocations.Details           = new WSHCEV_main.DestinationListRQDetails();
                        rqlocations.Details.Criterion = new WSHCEV_main.DestinationListRQDetailsCriterion();

                        if (parent == null)
                        {
                            rqlocations.Details.Criterion.DestinationType = "NMO.HTL.DST.CTR";
                        }
                        else
                        {
                            switch (parent.DestinationType)
                            {
                            case DestinationType.State:
                                rqlocations.Details.Criterion.DestinationType   = "NMO.HTL.DST.CTY";    // No hay regiones, se buscan directamente las ciudades
                                rqlocations.Details.Criterion.DestinationFilter = new WSHCEV_main.Destination()
                                {
                                    Sequence = 1, DestinationType = "NMO.HTL.DST.CTR", DestinationCode = parent.DestinationId
                                };
                                break;

                            case DestinationType.Region:
                                rqlocations.Details.Criterion.DestinationType   = "NMO.HTL.DST.CTY";
                                rqlocations.Details.Criterion.DestinationFilter = new WSHCEV_main.Destination()
                                {
                                    Sequence = 1, DestinationType = "NMO.HTL.DST.ARE", DestinationCode = parent.DestinationId
                                };
                                break;

                            case DestinationType.City:
                                rqlocations.Details.Criterion.DestinationType   = "NMO.HTL.DST.CTY";
                                rqlocations.Details.Criterion.DestinationFilter = new WSHCEV_main.Destination()
                                {
                                    Sequence = 1, DestinationType = "NMO.HTL.DST.CTY", DestinationCode = parent.DestinationId
                                };
                                break;
                            }
                        }

                        xw.Formatting = System.Xml.Formatting.None;
                        x.Serialize(xw, rqlocations);

                        wsRnd.Timeout = 30000;
                        var response = wsRnd.DestinationList(sw.ToString());
                        var sr       = new System.IO.StringReader(response);

                        x = new System.Xml.Serialization.XmlSerializer(typeof(WSHCEV_main.DestinationListRS));
                        var DestinationListRS = (WSHCEV_main.DestinationListRS)x.Deserialize(sr);
                        sr.Close();

                        if (DestinationListRS != null && DestinationListRS.Item is WSHCEV_main.DestinationListRSDetails &&
                            ((WSHCEV_main.DestinationListRSDetails)DestinationListRS.Item).Destinations.Destination != null)
                        {
                            var filteredDestination = ((WSHCEV_main.DestinationListRSDetails)DestinationListRS.Item).Destinations.Destination.Where(d => d.Value != "Argentina").Select(d => new DestinationModel {
                                DestinationId   = d.DestinationCode,
                                DestinationName = d.Value,
                                DestinationType = MapToDestinationType(d.DestinationType)
                            });

                            if (parent == null)
                            {
                                CacheData.Countries = filteredDestination.ToList();
                                CacheData.CountryListLastModification = DateTime.Now;
                            }

                            filteredDestination = filteredDestination.Where(d => d.DestinationName.PrepareNonStrictCompararison().Contains(destinationName.PrepareNonStrictCompararison()));

                            destinations = filteredDestination.ToList();
                        }
                    }
                    else
                    {
                        if (parent == null)
                        {
                            destinations = CacheData.Countries.Where(d => d.DestinationName.PrepareNonStrictCompararison().Contains(destinationName.PrepareNonStrictCompararison())).ToList();
                        }
                    }
                }
                catch (Exception ex)
                {
                }

                results.Destinations = destinations;

                return(results);
            }
            public ReservationModel Reserve(ReservationModel reservationModel, CheckArgentina.Models.Credential userCredential)
            {
                var wsRnd = new ServicioPruebaHeredado();

                var roomTypes = CacheData.NemoRoomTypes;

                try
                {
                    foreach (var vacancy in reservationModel.Vacancies)
                    {
                        var rqHotelBookService = new WSHCEV_main.HotelBookServiceRQ();
                        var x  = new System.Xml.Serialization.XmlSerializer(rqHotelBookService.GetType());
                        var sw = new System.IO.StringWriter();
                        var xw = new System.Xml.XmlTextWriter(sw);

                        rqHotelBookService.Source = new WSHCEV_main.Source();
                        rqHotelBookService.Source.PricingSurferConfiguration = new WSHCEV_main.PricingSurferConfiguration();
                        rqHotelBookService.Source.PricingSurferConfiguration.PreferedLanguage            = new WSHCEV_main.PreferedLanguage();
                        rqHotelBookService.Source.PricingSurferConfiguration.PreferedCurrency            = new WSHCEV_main.PreferedCurrency();
                        rqHotelBookService.Source.PricingSurferConfiguration.ResponseSet                 = new WSHCEV_main.ResponseSet();
                        rqHotelBookService.Source.PricingSurferConfiguration.ResponseSet.SortingCriteria = new WSHCEV_main.SortingCriteria();
                        rqHotelBookService.Source.PricingSurferConfiguration.ContractId = 10273; // 10857;
                        rqHotelBookService.Source.PricingSurferConfiguration.PreferedLanguage.LanguageCode          = "es";
                        rqHotelBookService.Source.PricingSurferConfiguration.PreferedCurrency.CurrencyCode          = "USD";
                        rqHotelBookService.Source.PricingSurferConfiguration.ResponseSet.FirstItem                  = 1;
                        rqHotelBookService.Source.PricingSurferConfiguration.ResponseSet.ItemsPerPage               = 10000;
                        rqHotelBookService.Source.PricingSurferConfiguration.ResponseSet.SortingCriteria.ItemsCount = 1;
                        rqHotelBookService.Source.PricingSurferConfiguration.ResponseSet.SortingCriteria.SortField  = new WSHCEV_main.SortField[] { new WSHCEV_main.SortField {
                                                                                                                                                        Sequence = 1, OrderBy = "ASC", SortFieldName = "name"
                                                                                                                                                    } };

                        var bookingService = new WSHCEV_main.BookingService();

                        bookingService.BookingServiceAgent = new WSHCEV_main.BookingServiceAgent
                        {
                            PersonNames = new WSHCEV_main.PersonNames
                            {
                                ItemsCount = 1,
                                PersonName = new WSHCEV_main.PersonName[]
                                {
                                    new WSHCEV_main.PersonName
                                    {
                                        Sequence = 1,
                                        NameType = "NMO.GBL.PNT.FIR",
                                        Value    = "Ineltur"
                                    }
                                }
                            },
                            Identifiers = new WSHCEV_main.Identifiers
                            {
                                ItemsCount = 1,
                                Identifier = new WSHCEV_main.Identifier[]
                                {
                                    new WSHCEV_main.Identifier
                                    {
                                        Sequence = 1,
                                        Type     = "NMO.HTL.RPT.CUT",
                                        Value    = "111111111111" //TODO:Colocar el CUIT
                                    }
                                }
                            }
                        };

                        bookingService.Client = new WSHCEV_main.Client
                        {
                            Sequence    = 1,
                            PersonNames = new WSHCEV_main.PersonNames
                            {
                                ItemsCount = 2,
                                PersonName = new WSHCEV_main.PersonName[]
                                {
                                    new WSHCEV_main.PersonName
                                    {
                                        Sequence = 1,
                                        NameType = "NMO.GBL.PNT.FIR",
                                        Value    = reservationModel.ReservationOwner.TravelerFirstName
                                    },
                                    new WSHCEV_main.PersonName
                                    {
                                        Sequence = 2,
                                        NameType = "NMO.GBL.PNT.LAS",
                                        Value    = reservationModel.ReservationOwner.TravelerLastName
                                    }
                                }
                            },
                            Identifiers = new WSHCEV_main.Identifiers
                            {
                                ItemsCount = 1,
                                Identifier = new WSHCEV_main.Identifier[]
                                {
                                    new WSHCEV_main.Identifier
                                    {
                                        Sequence = 1,
                                        Type     = MapFromIdType(reservationModel.ReservationOwner.TravelerIdType), //TODO:Mapear el tipo de ID
                                        Value    = reservationModel.ReservationOwner.TravelerId
                                    }
                                }
                            },

                            AgeSpecified = true,
                            AgeType      = "NMO.GBL.AGT.ADT",
                            Age          = (uint)(DateTime.Today - DateTime.Parse(reservationModel.ReservationOwner.TravelerBornDate)).TotalDays / 365
                        };

                        bookingService.BookingServiceItems = new WSHCEV_main.BookingServiceItems
                        {
                            ItemsCount         = 1,
                            BookingServiceItem = reservationModel.Vacancies.Select(v => new WSHCEV_main.BookingServiceItem
                            {
                                Sequence           = 1,
                                SupplierID         = reservationModel.LodgingSupplierId,
                                DestinationDetails = new WSHCEV_main.DestinationDetails
                                {
                                    ItemsCount  = 1,
                                    Destination = new WSHCEV_main.Destination[]
                                    {
                                        new WSHCEV_main.Destination
                                        {
                                            Sequence        = 1,
                                            DestinationCode = reservationModel.DestinationId,
                                            DestinationType = "NMO.HTL.DST.CTY"
                                        }
                                    }
                                },
                                CheckIn  = v.VacancyCheckin,
                                CheckOut = v.VacancyCheckout,
                                Rate     = new WSHCEV_main.BookingServiceRate
                                {
                                    RateID = v.VacancyId,
                                    Rooms  = new WSHCEV_main.BookingServiceRooms
                                    {
                                        Room = v.Rooms.Select(r => new WSHCEV_main.BookingServiceRoom
                                        {
                                            RoomDescription = new WSHCEV_main.RoomDescription
                                            {
                                                RoomType = MapFromRoomType(r.RoomType)
                                            },
                                            Occupancy = new WSHCEV_main.BookingServiceOccupancy
                                            {
                                                RoomsCount    = (uint)vacancy.VacancyReserved,
                                                AdultsCount   = GetAdultsByRoomType(r.RoomType),
                                                ChildrenCount = (uint)r.ChildrenAges.Count(),
                                                Guests        = new WSHCEV_main.BookingServiceGuests
                                                {
                                                    Guest = GetRequestBookingGuests(r.Travelers).ToArray()
                                                }
                                            }
                                        }).ToArray()
                                    }
                                }
                            }).ToArray()
                        };

                        rqHotelBookService.Details = new WSHCEV_main.BookingService[] { bookingService };

                        xw.Formatting = System.Xml.Formatting.None;
                        x.Serialize(xw, rqHotelBookService);

                        wsRnd.Timeout = 30000;
                        var response = wsRnd.HotelAvail(sw.ToString());
                        var sr       = new StringReader(response);

                        x = new System.Xml.Serialization.XmlSerializer(typeof(WSHCEV_main.HotelBookServiceRS));
                        var lodgingListRS = (WSHCEV_main.HotelBookServiceRS)x.Deserialize(sr);
                        sr.Close();

                        if (lodgingListRS != null && lodgingListRS.Item is WSHCEV_main.HotelBookServiceRSDetails &&
                            ((WSHCEV_main.HotelBookServiceRSDetails)lodgingListRS.Item).BookingService != null)
                        {
                            var responseBookingService = ((WSHCEV_main.HotelBookServiceRSDetails)lodgingListRS.Item).BookingService;

                            foreach (var book in responseBookingService)
                            {
                                //vacancy. book.BookingServiceItems.BookingServiceItem
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }

                return(reservationModel);
            }
            public ReservationModel BlockVacancies(ReservationModel reservationModel, CheckArgentina.Models.Credential userCredential)
            {
                var ticks = DateTime.Now.Ticks.ToString();

                reservationModel.ReservationId = ticks.Substring(0, Math.Min(ticks.Length, 16));

                return(reservationModel);
            }