Beispiel #1
0
            public LodgingListModel SearchLodging(SearchLodgingRequestModel searchLodgingRequestModel, Credential userCredential)
            {
                SessionData.SearchType = SearchType.National;

                var results  = new LodgingListModel();
                var lodgings = new List <LodgingModel>();

                var petition = new PeticionBuscarAlojamientos();

                CompletePetition(petition, userCredential);

                if (!string.IsNullOrEmpty(searchLodgingRequestModel.DestinationId))
                {
                    petition.IdDestino = Guid.Parse(searchLodgingRequestModel.DestinationId);
                }

                petition.TipoDestino = (TipoDestino)Enum.Parse(typeof(TipoDestino), searchLodgingRequestModel.DestinationType);

                petition.FechaInicio = searchLodgingRequestModel.Checkin;
                petition.FechaFin    = searchLodgingRequestModel.Checkout;
                foreach (var room in searchLodgingRequestModel.Rooms)
                {
                    switch (room.RoomType)
                    {
                    case RoomType.Single:
                    case RoomType.DSU:
                        petition.Habitacion1 = petition.Habitacion1 ?? 0 + room.Count;
                        break;

                    case RoomType.Double:
                    case RoomType.Twin:
                        petition.Habitacion2 = petition.Habitacion2 ?? 0 + room.Count;
                        break;

                    case RoomType.Triple:
                        petition.Habitacion3 = petition.Habitacion3 ?? 0 + room.Count;
                        break;

                    case RoomType.Quad:
                        petition.Habitacion4 = petition.Habitacion4 ?? 0 + room.Count;
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(searchLodgingRequestModel.Order))
                {
                    petition.Orden = (OrdenAlojamientos)Enum.Parse(typeof(OrdenAlojamientos), searchLodgingRequestModel.Order);
                }
                if (!string.IsNullOrEmpty(searchLodgingRequestModel.Nationality))
                {
                    petition.Nacionalidad = searchLodgingRequestModel.Nationality;
                }
                if (!string.IsNullOrEmpty(searchLodgingRequestModel.LodgingName) && searchLodgingRequestModel.LodgingName != "{}")
                {
                    petition.NombreAlojamiento = searchLodgingRequestModel.LodgingName;
                }

                var petitionResults = _service.BuscarAlojamientosEInfo(petition);

                if (petitionResults.Estado == EstadoRespuesta.Ok)
                {
                    foreach (var lodging in petitionResults.AlojamientosDisponibles)
                    {
                        if (searchLodgingRequestModel.LodgingName == "{}" || lodging.Nombre.ToLower().Contains((searchLodgingRequestModel.LodgingName ?? string.Empty).ToLower()))
                        {
                            var lodgingModel = new LodgingModel
                            {
                                LodgingId          = lodging.IdAlojamiento.ToString(),
                                LodgingName        = lodging.Nombre,
                                LodgingDescription = lodging.Alojamiento.Descripcion,
                                LodgingLocation    = lodging.Alojamiento.Direccion,
                                LodgingCity        = lodging.Destino.NombreDestino,
                                LodgingPhone       = lodging.Alojamiento.Telefono,
                                LodgingServices    = lodging.Alojamiento.Amenidades,
                                LodgingCategory    = GetCategory(lodging.Alojamiento.Categoria),
                                LodgingPhoto       = lodging.Alojamiento.FotoAlojamientoUrl,
                                LodgingPrice       = CalculateTotalPrice(lodging, petition.Habitacion1 ?? 0, petition.Habitacion2 ?? 0,
                                                                         petition.Habitacion3 ?? 0, petition.Habitacion4 ?? 0, 0, 0),
                                LodgingUnderPetition      = lodging.Alojamiento.BajoPeticion,
                                LodgingCancelationPolitic = lodging.Alojamiento.PoliticasCancelacion
                            };

                            var currency = "$";

                            switch (lodging.Moneda.GetValueOrDefault())
                            {
                            case Moneda.ARS: currency = "$"; break;

                            case Moneda.EUR: currency = "€"; break;

                            case Moneda.USD: currency = "U$S"; break;
                            }

                            lodgingModel.LodgingCurrency     = currency;
                            lodgingModel.LodgingCurrencyCode = MapCurrencyToNPS(lodging.Moneda.GetValueOrDefault());

                            var vacancies = new List <VacancyModel>();

                            var vacancyGroups = lodging.Alojamiento.Unidades.GroupBy(u => u.IdUnidad);

                            foreach (var group in vacancyGroups)
                            {
                                var vacancy = group.Select(v => new VacancyModel
                                {
                                    LodgingId       = lodgingModel.LodgingId,
                                    LodgingName     = lodgingModel.LodgingName,
                                    LodgingCurrency = lodgingModel.LodgingCurrency,
                                    VacancySelected = false,
                                    VacancyId       = v.IdUnidad.ToString(),
                                    VacancyName     = v.NombreUnidad,
                                    VacancyAdults   = v.Personas,
                                    VacancyBeds     = v.Camas,
                                    VacancyCount    = v.Disponibles,
                                    //VacancyPrice = Decimal.Round(v.MontoPorUnidad, 0),
                                    VacancyCheckin  = searchLodgingRequestModel.Checkin,
                                    VacancyCheckout = searchLodgingRequestModel.Checkout,
                                    VacancyDates    = group.Select(vg => vg.Fecha).ToList(),


                                    Available             = true,
                                    ConfirmedVacancyPrice = v.MontoPorUnidadRaCdTr,

                                    Rooms = new List <RoomModel> {
                                        new RoomModel {
                                            RoomId     = v.IdUnidad.ToString(),
                                            RoomName   = v.NombreUnidad,
                                            RoomAdults = v.Personas,
                                            RoomBeds   = v.Camas,
                                            RoomCount  = v.Disponibles
                                        }
                                    }
                                }).First();

                                vacancies.Add(vacancy);
                            }

                            lodgingModel.Vacancies = vacancies;

                            lodgings.Add(lodgingModel);
                        }
                    }
                }

                results.Lodgings = lodgings;

                return(results);
            }
Beispiel #2
0
        public LodgingListModel SearchHotels(SearchLodgingRequestModel searchLodgingRequestModel, Credential userCredential)
        {
            var lodgings = new List <LodgingModel>();
            var results  = new LodgingListModel();
            var petition = new PeticionBuscarAlojamientos();

            CompletePetition(petition, userCredential);
            if (!string.IsNullOrEmpty(searchLodgingRequestModel.DestinationId))
            {
                petition.IdDestino = Guid.Parse(searchLodgingRequestModel.DestinationId);
            }

            //petition.TipoDestino = (TipoDestino)Enum.Parse(typeof(TipoDestino), searchLodgingRequestModel.DestinationType);

            using (var dc = new TurismoDataContext())
            {
                var ciudad = dc.Ciudads.Where(c => c.IDCIUDAD.ToString() == searchLodgingRequestModel.DestinationId).ToArray();
                if (ciudad.Length != 0)
                {
                    petition.TipoDestino = (TipoDestino)Enum.Parse(typeof(TipoDestino), "Ciudad");
                }
                else
                {
                    petition.TipoDestino = (TipoDestino)Enum.Parse(typeof(TipoDestino), "Provincia");
                }
            }

            petition.FechaInicio        = searchLodgingRequestModel.Checkin;
            petition.FechaFin           = searchLodgingRequestModel.Checkout;
            petition.desayuno           = searchLodgingRequestModel.Breakfast;
            petition.tarifaReembolsable = searchLodgingRequestModel.Tarifa;

            if (searchLodgingRequestModel.Rooms == null)
            {
                petition.Habitacion1 = petition.Habitacion1 ?? 0;
                petition.Habitacion2 = petition.Habitacion2 ?? 0;
                petition.Habitacion3 = petition.Habitacion3 ?? 0;
                petition.Habitacion4 = petition.Habitacion4 ?? 0 + 1;
                petition.Habitacion5 = petition.Habitacion5 ?? 0 + 1;
                petition.Habitacion6 = petition.Habitacion6 ?? 0 + 1;
            }
            else
            {
                foreach (var room in searchLodgingRequestModel.Rooms)
                {
                    switch (room.RoomType)
                    {
                    case RoomType.Single:
                        petition.Habitacion1 = (petition.Habitacion1 ?? 0) + 1;
                        break;

                    case RoomType.Double:
                        petition.Habitacion2 = (petition.Habitacion2 ?? 0) + 1;
                        break;

                    case RoomType.Triple:
                        petition.Habitacion3 = (petition.Habitacion3 ?? 0) + 1;
                        break;

                    case RoomType.Quad:
                        petition.Habitacion4 = (petition.Habitacion4 ?? 0) + 1;
                        break;
                    }
                }
            }

            if (!string.IsNullOrEmpty(searchLodgingRequestModel.Order))
            {
                petition.Orden = (OrdenAlojamientos)Enum.Parse(typeof(OrdenAlojamientos), searchLodgingRequestModel.Order);
            }

            if (!string.IsNullOrEmpty(searchLodgingRequestModel.Nationality))
            {
                petition.Nacionalidad = searchLodgingRequestModel.Nationality;
            }

            if (!string.IsNullOrEmpty(searchLodgingRequestModel.LodgingName) && searchLodgingRequestModel.LodgingName != "{}")
            {
                petition.NombreAlojamiento = searchLodgingRequestModel.LodgingName;
            }

            var petitionResults = _service.SearchHotels(petition);

            if (petitionResults.Estado == EstadoRespuesta.Ok)
            {
                foreach (var lodging in petitionResults.AlojamientosDisponibles)
                {
                    if (searchLodgingRequestModel.LodgingName == "{}" || lodging.Nombre.ToLower().Contains((searchLodgingRequestModel.LodgingName ?? string.Empty).ToLower()))
                    {
                        var lodgingModel = new LodgingModel
                        {
                            DestinationId             = lodging.Destino.IdDestino.ToString(),
                            LodgingId                 = lodging.IdAlojamiento.ToString(),
                            LodgingName               = lodging.Nombre,
                            LodgingDescription        = lodging.Alojamiento.Descripcion,
                            LodgingLocation           = lodging.Alojamiento.Direccion,
                            LodgingCity               = lodging.Destino.NombreDestino,
                            LodgingPhone              = lodging.Alojamiento.Telefono,
                            LodgingPrice              = Math.Round(Decimal.Parse(lodging.Tarifa1.ToString()), 0),
                            LodgingServices           = lodging.Alojamiento.Amenidades,
                            LodgingCategory           = GetCategory(lodging.Alojamiento.Categoria),
                            LodgingUnderPetition      = lodging.Alojamiento.BajoPeticion,
                            LodgingCancelationPolitic = lodging.Alojamiento.PoliticasCancelacion,
                            //LodgingBreakfast = searchLodgingRequestModel.Breakfast,
                            //LodgingTarifa = searchLodgingRequestModel.Tarifa
                        };
                        var currency = "$";

                        switch (lodging.Moneda.GetValueOrDefault())
                        {
                        case Moneda.ARS: currency = "$"; break;

                        case Moneda.EUR: currency = "€"; break;

                        case Moneda.USD: currency = "U$S"; break;
                        }

                        lodgingModel.LodgingCurrency     = currency;
                        lodgingModel.LodgingCurrencyCode = MapCurrencyToNPS(lodging.Moneda.GetValueOrDefault());
                        if (lodging.Alojamiento.Unidades != null)
                        {
                            var vacancies = new List <VacancyModel>();

                            var vacancyGroups = lodging.Alojamiento.Unidades.GroupBy(u => u.IdUnidad);

                            foreach (var group in vacancyGroups)
                            {
                                var vacancy = group.Select(v => new VacancyModel
                                {
                                    LodgingId           = lodgingModel.LodgingId,
                                    LodgingName         = lodgingModel.LodgingName,
                                    LodgingCurrency     = lodgingModel.LodgingCurrency,
                                    VacancySelected     = false,
                                    VacancyId           = v.IdUnidad.ToString(),
                                    VacancyName         = v.NombreUnidad,
                                    VacancyAdults       = v.Personas,
                                    VacancyBeds         = v.Camas,
                                    VacancyCount        = v.Disponibles,
                                    VacancyPriceRaCdTr  = Decimal.Round(v.MontoPorUnidadRaCdTr, 0),
                                    VacancyPriceRaCdTnr = Decimal.Round(v.MontoPorUnidadRaCdTnr, 0),
                                    VacancyPriceRaSdTr  = Decimal.Round(v.MontoPorUnidadRaSdTr, 0),
                                    VacancyPriceRaSdTnr = Decimal.Round(v.MontoPorUnidadRaSdTnr, 0),
                                    VacancyPriceExCdTr  = Decimal.Round(v.MontoPorUnidadExCdTr, 0),
                                    VacancyPriceExCdTnr = Decimal.Round(v.MontoPorUnidadExCdTnr, 0),
                                    VacancyPriceExSdTr  = Decimal.Round(v.MontoPorUnidadExSdTr, 0),
                                    VacancyPriceExSdTnr = Decimal.Round(v.MontoPorUnidadExSdTnr, 0),
                                    VacancyPriceMeCdTr  = Decimal.Round(v.MontoPorUnidadMeCdTr, 0),
                                    VacancyPriceMeCdTnr = Decimal.Round(v.MontoPorUnidadMeCdTnr, 0),
                                    VacancyPriceMeSdTr  = Decimal.Round(v.MontoPorUnidadMeSdTr, 0),
                                    VacancyPriceMeSdTnr = Decimal.Round(v.MontoPorUnidadMeSdTnr, 0),
                                    VacancyCheckin      = searchLodgingRequestModel.Checkin,
                                    VacancyCheckout     = searchLodgingRequestModel.Checkout,
                                    VacancyDates        = group.Select(vg => vg.Fecha).ToList(),
                                    //Breakfast = v.Desayuno,
                                    //Tarifa = v.Tarifa,
                                    Available             = true,
                                    ConfirmedVacancyPrice = 0,
                                    Promociones           = v.Promociones.Select(p => new Promociones_Alojamiento
                                    {
                                        ACTIVO                 = p.Activo,
                                        DESCRIPCION            = p.Descripcion1,
                                        DESCRIPCION2           = p.Descripcion2,
                                        DESCUENTO              = p.Descuento,
                                        DIASACOBRAR            = p.DiasACobrar,
                                        DIASRESERVADOS         = p.DiasReservados,
                                        FECHAFIN               = p.FechaFin,
                                        FECHAINICIO            = p.FechaInicio,
                                        IDALOJ                 = p.LodgingId,
                                        IDPROMOCION            = p.PromocionId,
                                        IDTIPOPUBLICACIONPROMO = p.TipoPromocionId,
                                        IDUNIDADPROMO          = p.IdUnidadPromo,
                                        MINIMONOCHES           = p.MinimoNoches,
                                        MAXIMONOCHES           = p.MaximoNoches,
                                        NOMBRE                 = p.NombrePromocion,
                                        SLOGAN                 = p.Slogan
                                    }).Where(p => p.FECHAFIN >= DateTime.Now.Date).ToArray(),
                                    Rooms = new List <RoomModel> {
                                        new RoomModel {
                                            RoomId     = v.IdUnidad.ToString(),
                                            RoomName   = v.NombreUnidad,
                                            RoomAdults = v.Personas,
                                            RoomBeds   = v.Camas,
                                            RoomCount  = v.Disponibles
                                        }
                                    }
                                }).First();

                                vacancies.Add(vacancy);
                            }
                            lodgingModel.Vacancies = vacancies;
                        }
                        lodgings.Add(lodgingModel);
                    }
                }
            }
            results.Lodgings = lodgings;
            return(results);
        }