Beispiel #1
0
        public object UpdateBingAddressGeocode(Location location, string culture)
        {
            DbGeography result = null;

            var address = new Bing.Geocode.Address()
            {
                AddressLine   = location.Address1,
                AdminDistrict = location.ISOStateCode,
                CountryRegion = location.ISOCountryCode,
                Locality      = location.City,
                PostalCode    = location.PostalCode
            };

            var bingAppId = GetBingAppId();

            var geocodeRequest = new Bing.Geocode.GeocodeRequest()
            {
                Address     = address,
                Credentials = new Bing.Geocode.Credentials()
                {
                    ApplicationId = bingAppId
                },
                Culture = FormatCulture(culture),
                Options = new Bing.Geocode.GeocodeOptions()
                {
                    Count   = 1,
                    Filters = new List <Bing.Geocode.FilterBase>()
                    {
                        new Bing.Geocode.ConfidenceFilter()
                        {
                            MinimumConfidence = Bing.Geocode.Confidence.Medium
                        }
                    }
                }
            };

            var geocodeServiceClient = new Bing.Geocode.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

            var geocodeResponse = geocodeServiceClient.Geocode(geocodeRequest);

            if (geocodeResponse != null && geocodeResponse.Results != null && geocodeResponse.Results.Any())
            {
                var geocodeResult = geocodeResponse.Results.FirstOrDefault();

                if (geocodeResult != null)
                {
                    var geocodeLocation = geocodeResult.Locations.FirstOrDefault();

                    if (geocodeLocation != null && geocodeLocation.Latitude != 0 && geocodeLocation.Longitude != 0)
                    {
                        result = GeographyUtils.GetPointFromLatitudeAndLongitude(( float )geocodeLocation.Latitude,
                                                                                 ( float )geocodeLocation.Longitude);
                    }
                }
            }
            location.Latitude  = ( float )(result != null ? result.Latitude ?? 0 : 0);
            location.Longitude = ( float )(result != null ? result.Longitude ?? 0 : 0);
            return(location);
        }
Beispiel #2
0
        public DbGeography GetBingAddressGeocode(string address1, string city, string state, string postalCode, string country, string culture)
        {
            DbGeography result = null;

            var address = new Bing.Geocode.Address()
            {
                AddressLine   = address1,
                AdminDistrict = state,
                CountryRegion = country,
                Locality      = city,
                PostalCode    = postalCode
            };
            var bingAppId = GetBingAppId();

            var geocodeRequest = new Bing.Geocode.GeocodeRequest()
            {
                Address     = address,
                Credentials = new Bing.Geocode.Credentials()
                {
                    ApplicationId = bingAppId
                },
                Culture = FormatCulture(culture),
                Options = new Bing.Geocode.GeocodeOptions()
                {
                    Count   = 1,
                    Filters = new List <Bing.Geocode.FilterBase>()
                    {
                        new Bing.Geocode.ConfidenceFilter()
                        {
                            MinimumConfidence = Bing.Geocode.Confidence.Medium
                        }
                    }
                }
            };

            Bing.Geocode.GeocodeServiceClient geocodeServiceClient = new Bing.Geocode.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

            var geocodeResponse = geocodeServiceClient.Geocode(geocodeRequest);

            if (geocodeResponse != null && geocodeResponse.Results != null && geocodeResponse.Results.Count() > 0)
            {
                var geocodeResult = geocodeResponse.Results.FirstOrDefault();

                if (geocodeResult != null)
                {
                    var geocodeLocation = geocodeResult.Locations.FirstOrDefault();

                    if (geocodeLocation != null && geocodeLocation.Latitude != 0 && geocodeLocation.Longitude != 0)
                    {
                        result = GeographyUtils.GetPointFromLatitudeAndLongitude(( float )geocodeLocation.Latitude,
                                                                                 ( float )geocodeLocation.Longitude);
                    }
                }
            }

            return(result);
        }
Beispiel #3
0
        public List <EnterpriseModel> GetEnterprisesWithTipsForHotel(int deviceId, float?hotelLatitude, float?hotelLongitude, float radiusInMeters)
        {
            List <EnterpriseModel> enterprises = null;

            DbGeography hotelPoint = null;

            if (hotelLatitude.HasValue && hotelLongitude.HasValue)
            {
                hotelPoint = GeographyUtils.GetPointFromLatitudeAndLongitude(hotelLatitude.Value, hotelLongitude.Value);
            }

            if (hotelPoint != null)
            {
                var list = Rp.ExecuteAction(() => (from e in ProxylessContext.Enterprises.Where(e2 => e2.IsActive)
                                                   let el = e.EnterpriseLocations.Where(el2 => el2.IsActive)
                                                            let ecm = e.EnterpriseCategoryMaps
                                                                      let fecm = ecm.FirstOrDefault()
                                                                                 let cm = ecm.Where(ecm2 => ecm2.CategoryMap.IsActive).Select(ecm2 => ecm2.CategoryMap)
                                                                                          let fcm = cm.FirstOrDefault()
                                                                                                    let hcm = cm.SelectMany(cm2 => cm2.HotelCategoryMaps.Where(hcm2 => hcm2.IsActive && hcm2.FKDevice == deviceId))
                                                                                                              let fhcm = hcm.OrderBy(hcm2 => hcm2.Ordinal).FirstOrDefault()
                                                                                                                         let eit = e.InsiderTips.Where(it2 => it2.IsActive && !it2.FKEnterpriseLocation.HasValue)
                                                                                                                                   let elit = el.SelectMany(el2 => el2.InsiderTips.Where(it2 => it2.IsActive))
                                                                                                                                              where el.Any(el2 => (!elit.Any() && el2.Coordinates.Distance(hotelPoint) < radiusInMeters) ||
                                                                                                                                                           elit.Select(hboelm2 => hboelm2.FKEnterpriseLocation).Contains(el2.PKID)) &&
                                                                                                                                              hcm.Any() &&
                                                                                                                                              (eit.Any() || elit.Any())
                                                                                                                                              select new
                {
                    CMImage = fcm.Image,
                    ECMImage = fecm.Image,
                    Enterprise = new EnterpriseModel
                    {
                        EnterpriseLocations = (from el2 in el
                                               let d = el2.Coordinates.Distance(hotelPoint)
                                                       where el2.Coordinates.Distance(hotelPoint) < radiusInMeters ||
                                                       elit.Select(hboelm2 => hboelm2.FKEnterpriseLocation).Contains(el2.PKID)
                                                       orderby d
                                                       select new EnterpriseLocationModel
                        {
                            DistanceInMeters = d,
                            Location = new LocationModel
                            {
                                Address1 = el2.Address1,
                                Address2 = el2.Address2,
                                City = el2.City,
                                ISOCountryCode = el2.Country,
                                Latitude = el2.Latitude,
                                Longitude = el2.Longitude,
                                PostalCode = el2.PostalCode,
                                ISOStateCode = el2.State,
                            },
                            Phone = el2.Phone,
                            PKID = el2.PKID,
                            Tips = (from elit2 in elit
                                    let c = elit2.ContactUser
                                            where el2.PKID == elit2.FKEnterpriseLocation
                                            select new TipModel
                            {
                                ContactUser = new ContactUserModel
                                {
                                    Name = c.ContactUserName,
                                    PKID = c.PKID
                                },
                                LastModified = elit2.TipDateTime,
                                LocalTip = elit2.Tip,
                                LocalTipLanguage = elit2.TipLanguage,
                                LocalTipXml = elit2.LocalizedTip,
                                PKID = elit2.PKID
                            })
                        }),
                        Name = e.Name,
                        PKID = e.PKID,
                        Tips = (from eit2 in eit
                                let c = eit2.ContactUser
                                        select new TipModel
                        {
                            ContactUser = new ContactUserModel
                            {
                                Name = c.ContactUserName,
                                PKID = c.PKID
                            },
                            LastModified = eit2.TipDateTime,
                            LocalTip = eit2.Tip,
                            LocalTipLanguage = eit2.TipLanguage,
                            LocalTipXml = eit2.LocalizedTip,
                            PKID = eit2.PKID
                        })
                    },
                    HCMImage = fhcm.Image,
                })).Take(10).ToList();

                list.ForEach(e =>
                {
                    if (e.Enterprise != null)
                    {
                        if (e.CMImage != null)
                        {
                            e.Enterprise.ListItemImage = new ImageModel(e.CMImage);
                        }

                        if (e.HCMImage != null)
                        {
                            e.Enterprise.ListItemImage = new ImageModel(e.HCMImage);
                        }

                        if (e.ECMImage != null)
                        {
                            e.Enterprise.ListItemImage = new ImageModel(e.ECMImage);
                        }

                        e.Enterprise.EnterpriseLocations.ForEach(el => el.Tips.ForEach(t => t.Tip = Localization.GetLocalizedText(t.LocalTip, t.LocalTipXml, t.LocalTipLanguage)));
                        e.Enterprise.Tips.ForEach(
                            t => t.Tip = Localization.GetLocalizedText(t.LocalTip, t.LocalTipXml, t.LocalTipLanguage));

                        if (enterprises == null)
                        {
                            enterprises = new List <EnterpriseModel>();
                        }

                        enterprises.Add(e.Enterprise);
                    }
                });
            }

            return(enterprises);
        }
Beispiel #4
0
        public List <EnterpriseModel> GetSearchRecommendedEnterprisesOnDevice(int deviceId, float?hotelLatitude, float?hotelLongitude, float radiusInMeters, int?categoryId, string text)
        {
            List <EnterpriseModel> enterprises = null;

            var hotelPoint = GeographyUtils.GetPointFromLatitudeAndLongitude(hotelLatitude, hotelLongitude);

            if (hotelPoint != null)
            {
                RootRepository.SecurityRepository.AssertDevicePermissions(deviceId);

                if (text != null)
                {
                    text = text.Trim();
                }

                var query = (from hboem in Context.HotelBestOfEnterpriseMaps
                             .Include(x => x.EnterpriseCategoryMap.CategoryMap)
                             .Include(x => x.EnterpriseCategoryMap.CategoryMap.HotelCategoryMaps)
                             .Include(x => x.EnterpriseCategoryMap.Enterprise)
                             .Include(x => x.EnterpriseCategoryMap.Enterprise.EnterpriseLocations)
                             .Include(x => x.EnterpriseCategoryMap.Enterprise.EnterpriseImageMaps.Select(eim => eim.Image))
                             .Include(x => x.HotelBestOfEnterpriseLocationMaps.Select(hboelm => hboelm.EnterpriseLocation))
                             where
                             hboem.IsActive &&
                             hboem.FKDevice == deviceId &&
                             hboem.EnterpriseCategoryMap.Enterprise.IsActive &&
                             hboem.EnterpriseCategoryMap.Enterprise.EnterpriseLocations.Any(x => x.IsActive) &&
                             hboem.EnterpriseCategoryMap.CategoryMap.IsActive &&
                             (!hboem.HotelBestOfEnterpriseLocationMaps.Any() || hboem.HotelBestOfEnterpriseLocationMaps.Any(x => x.EnterpriseLocation.IsActive))
                             select new
                {
                    CMImage = hboem.EnterpriseCategoryMap.CategoryMap.Image,
                    ECMImage = hboem.EnterpriseCategoryMap.Image,
                    Enterprise = new EnterpriseModel
                    {
                        Blacklisted = false,
                        Name = hboem.EnterpriseCategoryMap.Enterprise.Name,
                        PKID = hboem.EnterpriseCategoryMap.Enterprise.PKID,
                        Recommended = true,
                        EnterpriseLocations = hboem.EnterpriseCategoryMap.Enterprise.EnterpriseLocations.Where(x => x.IsActive).Select(x => new EnterpriseLocationModel
                        {
                            Blacklisted = false,
                            DistanceInMeters = x.Coordinates.Distance(hotelPoint),
                            Location = new LocationModel
                            {
                                Address1 = x.Address1,
                                Address2 = x.Address2,
                                City = x.City,
                                ISOCountryCode = x.Country,
                                Latitude = x.Latitude,
                                Longitude = x.Longitude,
                                PostalCode = x.PostalCode,
                                ISOStateCode = x.State,
                            },
                            Phone = x.Phone,
                            PKID = x.PKID,
                            Recommended = hboem.HotelBestOfEnterpriseLocationMaps.Any(hboelm2 => hboelm2.FKEnterpriseLocation == x.PKID)
                        })
                    },
                    HCMImage = hboem.EnterpriseCategoryMap.CategoryMap.HotelCategoryMaps.FirstOrDefault(x => x.FKDevice == deviceId).Image,
                    HotelCategoryMaps = hboem.EnterpriseCategoryMap.CategoryMap.HotelCategoryMaps.Where(x => x.FKDevice == deviceId)
                });

                //var query = ( from e in Context.Enterprises.Where( e2 => e2.IsActive )
                //			  let el = e.EnterpriseLocations.Where( el2 => el2.IsActive )
                //			  let ecm = e.EnterpriseCategoryMaps.Where( ecm2 => ecm2.IsActive )
                //			  let fecm = ecm.FirstOrDefault()
                //			  let cm = ecm.Where( ecm2 => ecm2.CategoryMap.IsActive ).Select( ecm2 => ecm2.CategoryMap )
                //			  let fcm = cm.FirstOrDefault()
                //			  let hcm = cm.SelectMany( cm2 => cm2.HotelCategoryMaps.Where( hcm2 => hcm2.IsActive && hcm2.FKDevice == deviceId ) )
                //			  let fhcm = hcm.OrderBy( hcm2 => hcm2.Ordinal ).FirstOrDefault()
                //			  let hboem = ecm.SelectMany( ecm2 => ecm2.HotelBestOfEnterpriseMaps.Where( hboem2 => hboem2.IsActive && hboem2.FKDevice == deviceId ).OrderBy( hboem2 => hboem2.Ordinal ) )
                //			  let hboelm = hboem.SelectMany( hboem2 => hboem2.HotelBestOfEnterpriseLocationMaps )
                //			  let blem = e.BlackListEnterpriseMaps.Where( blem2 => blem2.IsActive && blem2.FKDevice == deviceId )
                //			  let blelm = el.SelectMany( el2 => el2.BlackListEnterpriseLocationMaps.Where( blelm2 => blelm2.IsActive && blelm2.Hotel.Devices.Any( d => d.PKID == deviceId ) ) )
                //			  where el.Any( el2 => ( !hboelm.Any() && el2.Coordinates.Distance( hotelPoint ) < radiusInMeters )
                //					  || hboelm.Select( hboelm2 => hboelm2.FKEnterpriseLocation ).Contains( el2.PKID ) )
                //				  && hcm.Any()
                //				  && ( hboem.Any() || hboelm.Any() )
                //			  select new
                //			  {
                //				  CMImage = fcm.Image,
                //				  ECMImage = fecm.Image,
                //				  Enterprise = new EnterpriseModel
                //				  {
                //					  Blacklisted = blem.Any(),
                //					  EnterpriseLocations = ( from el2 in el
                //											  where ( !hboelm.Any() && el2.Coordinates.Distance( hotelPoint ) < radiusInMeters )
                //												  || hboelm.Select( hboelm2 => hboelm2.FKEnterpriseLocation ).Contains( el2.PKID )
                //											  select new EnterpriseLocationModel
                //											  {
                //												  Blacklisted = blelm.Select( blelm2 => blelm2.FKEnterpriseLocation ).Contains( el2.PKID ),
                //												  DistanceInMiles = Context.CalculateDistance( el2.Latitude, el2.Longitude, hotelGeocode.Latitude.Value, hotelGeocode.Longitude.Value ),
                //												  Location = new LocationModel
                //												  {
                //													  Address1 = el2.Address1,
                //													  Address2 = el2.Address2,
                //													  City = el2.City,
                //													  Country = new CountryModel
                //													  {
                //														  ISOCountryCode = el2.Country
                //													  },
                //													  Geocode = new GeocodeModel
                //													  {
                //														  Latitude = el2.Latitude,
                //														  Longitude = el2.Longitude
                //													  },
                //													  PostalCode = el2.PostalCode,
                //													  State = new StateModel
                //													  {
                //														  ISOStateCode = el2.State,
                //													  }
                //												  },
                //												  Phone = el2.Phone,
                //												  PKID = el2.PKID,
                //												  Recommended = hboelm.Any( hboelm2 => hboelm2.FKEnterpriseLocation == el2.PKID )
                //											  } ),
                //					  Name = e.Name,
                //					  PKID = e.PKID,
                //					  Recommended = hboem.Any() && !hboelm.Any()
                //				  },
                //				  HCMImage = fhcm.Image,
                //				  HotelCategoryMaps = hcm
                //			  } );

                if (categoryId.HasValue)
                {
                    query = (from q in query
                             where q.HotelCategoryMaps.Any(hcm => hcm.CategoryMap.FKChildCategory == categoryId.Value)
                             select q);
                }

                if (!string.IsNullOrWhiteSpace(text))
                {
                    query = (from q in query
                             let gebft = Context.GetEnterprisesByFreeText(text).Select(gebft => gebft.Key)
                                         where gebft.Contains(q.Enterprise.PKID)
                                         select q);
                }

                var list = query.Take(20).ToList();

                list.ForEach(e =>
                {
                    if (e.Enterprise != null)
                    {
                        if (e.CMImage != null)
                        {
                            e.Enterprise.ListItemImage = new ImageModel(e.CMImage);
                        }

                        if (e.HCMImage != null)
                        {
                            e.Enterprise.ListItemImage = new ImageModel(e.HCMImage);
                        }

                        if (e.ECMImage != null)
                        {
                            e.Enterprise.ListItemImage = new ImageModel(e.ECMImage);
                        }

                        if (enterprises == null)
                        {
                            enterprises = new List <EnterpriseModel>();
                        }

                        enterprises.Add(e.Enterprise);
                    }
                });
            }

            return(enterprises);
        }
Beispiel #5
0
        public List <EnterpriseModel> GetRecommendedEnterprisesOnDevice(int deviceId, float?hotelLatitude, float?hotelLongitude, float radiusInMeters)
        {
            List <EnterpriseModel> enterprises = null;

            var hotelPoint = GeographyUtils.GetPointFromLatitudeAndLongitude(hotelLatitude, hotelLongitude);

            if (hotelPoint != null)
            {
                RootRepository.SecurityRepository.AssertDevicePermissions(deviceId);

                enterprises = Rp.ExecuteAction(() => (from e in ProxylessContext.Enterprises.Where(e2 => e2.IsActive)
                                                      let el = e.EnterpriseLocations.Where(el2 => el2.IsActive && el2.Coordinates.Distance(hotelPoint) < radiusInMeters)
                                                               let ecm = e.EnterpriseCategoryMaps
                                                                         let fecm = ecm.FirstOrDefault()
                                                                                    let cm = ecm.Where(ecm2 => ecm2.CategoryMap.IsActive).Select(ecm2 => ecm2.CategoryMap)
                                                                                             let fcm = cm.FirstOrDefault()
                                                                                                       let hcm = cm.SelectMany(cm2 => cm2.HotelCategoryMaps.Where(hcm2 => hcm2.IsActive && hcm2.FKDevice == deviceId))
                                                                                                                 let fhcm = hcm.OrderBy(hcm2 => hcm2.Ordinal).FirstOrDefault()
                                                                                                                            let hboem = ecm.SelectMany(ecm2 => ecm2.HotelBestOfEnterpriseMaps.Where(hboem2 => hboem2.IsActive && hboem2.FKDevice == deviceId).OrderBy(hboem2 => hboem2.Ordinal))
                                                                                                                                        let hboelm = hboem.SelectMany(hboem2 => hboem2.HotelBestOfEnterpriseLocationMaps)
                                                                                                                                                     where el.Any(el2 => (!hboelm.Any() && el2.Coordinates.Distance(hotelPoint) < radiusInMeters) ||
                                                                                                                                                                  hboelm.Select(hboelm2 => hboelm2.FKEnterpriseLocation).Contains(el2.PKID)) &&
                                                                                                                                                     hcm.Any() &&
                                                                                                                                                     (hboem.Any() || hboelm.Any())
                                                                                                                                                     orderby hboem.Min(hboem2 => hboem2.Ordinal),
                                                      hboelm.Min(hboelm2 => hboelm2.Ordinal)
                                                      select new EnterpriseModel
                {
                    EnterpriseLocations = (from el2 in el
                                           where (!hboelm.Any() && el2.Coordinates.Distance(hotelPoint) < radiusInMeters) ||
                                           hboelm.Select(hboelm2 => hboelm2.FKEnterpriseLocation).Contains(el2.PKID)
                                           select new EnterpriseLocationModel
                    {
                        DistanceInMeters = el2.Coordinates.Distance(hotelPoint),
                        Location = new LocationModel
                        {
                            Address1 = el2.Address1,
                            Address2 = el2.Address2,
                            City = el2.City,
                            ISOCountryCode = el2.Country,
                            Latitude = el2.Latitude,
                            Longitude = el2.Longitude,
                            PostalCode = el2.PostalCode,
                            ISOStateCode = el2.State
                        },
                        Phone = el2.Phone,
                        PKID = el2.PKID,
                        Recommended = hboelm.Any(hboelm2 => hboelm2.FKEnterpriseLocation == el2.PKID),
                        RecommendedCategories = (from hboelm2 in hboelm
                                                 select new OrderModel
                        {
                            Key = hboelm2.HotelBestOfEnterpriseMap.EnterpriseCategoryMap.CategoryMap.ChildCategory.PKID,
                            Order = hboelm2.Ordinal
                        })
                    }),
                    Name = e.Name,
                    PKID = e.PKID,
                    Recommended = hboem.Any() && !hboelm.Any(),
                    RecommendedCategories = (from hboem2 in hboem
                                             select new OrderModel
                    {
                        Key = hboem2.EnterpriseCategoryMap.CategoryMap.ChildCategory.PKID,
                        Order = hboem2.Ordinal
                    })
                })).ToList();
            }

            return(enterprises);
        }
Beispiel #6
0
        public EnterpriseModel GetEnterpriseForEdit(int deviceId, int enterpriseId, int?enterpriseLocationId,
                                                    float?hotelLatitude, float?hotelLongitude, float radiusInMeters)
        {
            EnterpriseModel enterprise = null;

            var hotelPoint = GeographyUtils.GetPointFromLatitudeAndLongitude(hotelLatitude, hotelLongitude);

            if (hotelPoint != null)
            {
                RootRepository.SecurityRepository.AssertDevicePermissions(deviceId);

                // TODO: JD: Culture.
                var culture = MvcApplication.GetCurrentCulture();

                var nativeLanguage = culture.Substring(0, 2).ToUpper();

                var item =
                    Rp.ExecuteAction(
                        () => (from e in ProxylessContext.Enterprises.Where(e2 => e2.IsActive && e2.PKID == enterpriseId)
                               let eim = e.EnterpriseImageMaps.Where(eim2 => eim2.IsActive)
                                         let el = e.EnterpriseLocations.Where(el2 => el2.IsActive && (!enterpriseLocationId.HasValue || el2.PKID == enterpriseLocationId.Value))
                                                  let ecm = e.EnterpriseCategoryMaps
                                                            let fecm = ecm.FirstOrDefault()
                                                                       let cm = ecm.Where(ecm2 => ecm2.CategoryMap.IsActive).Select(ecm2 => ecm2.CategoryMap)
                                                                                let fcm = cm.FirstOrDefault()
                                                                                          let hcm = cm.SelectMany(cm2 => cm2.HotelCategoryMaps.Where(hcm2 => hcm2.IsActive && hcm2.FKDevice == deviceId))
                                                                                                    let fhcm = hcm.OrderBy(hcm2 => hcm2.Ordinal).FirstOrDefault()
                                                                                                               let hboem = ecm.SelectMany(ecm2 => ecm2.HotelBestOfEnterpriseMaps.Where(hboem2 => hboem2.IsActive && hboem2.FKDevice == deviceId).OrderBy(hboem2 => hboem2.Ordinal))
                                                                                                                           let hboelm = hboem.SelectMany(hboem2 => hboem2.HotelBestOfEnterpriseLocationMaps)
                                                                                                                                        select new
                {
                    CMImage = fcm.Image,
                    ECMImage = fecm.Image,
                    Enterprise = new EnterpriseModel
                    {
                        EnterpriseLocations = (from el2 in el
                                               let c = ProxylessContext.Countries.FirstOrDefault(c2 => c2.IsActive && c2.ISOCountryCode == el2.Country)
                                                       let s =
                                                   ProxylessContext.States.FirstOrDefault(
                                                       s2 => s2.IsActive && s2.ISOStateCode == el2.State && s2.FKCountry == c.PKID)
                                                   select new EnterpriseLocationModel
                        {
                            BingId = el2.BingId,
                            DistanceInMeters = el2.Coordinates.Distance(hotelPoint),
                            HourType = el2.HourType,
                            LocalHours = el2.Hours,
                            LocalHoursLanguage = !string.IsNullOrEmpty(el2.HoursLanguage) ? el2.HoursLanguage : nativeLanguage,
                            LocalHoursXml = el2.LocalizedHours,
                            Location = new LocationModel
                            {
                                Address1 = el2.Address1,
                                Address2 = el2.Address2,
                                City = el2.City,
                                Country = c,
                                Latitude = el2.Latitude,
                                Longitude = el2.Longitude,
                                PostalCode = el2.PostalCode,
                                State = s
                            },
                            Phone = el2.Phone,
                            PhoneISOCountryCode = el2.PhoneISOCountryCode,
                            PKID = el2.PKID,
                            Recommended = hboelm.Any(hboelm2 => hboelm2.FKEnterpriseLocation == el2.PKID)
                        }),
                        LocalDescription = e.Description,
                        LocalDescriptionLanguage =
                            e.DescriptionLanguage != null && e.DescriptionLanguage != string.Empty
                                                                                                ? e.DescriptionLanguage
                                                                                                : nativeLanguage,
                        LocalDescriptionXml = e.LocalizedDescription,
                        Name = e.Name,
                        PKID = e.PKID,
                        Recommended = hboem.Any() && !hboelm.Any()
                    },
                    EnterpriseImages = eim.Select(eim2 => eim2.Image),
                    HCMImage = fhcm.Image,
                })).FirstOrDefault();

                if (item != null && item.Enterprise != null)
                {
                    if (item.EnterpriseImages != null)
                    {
                        foreach (var customImage in item.EnterpriseImages)
                        {
                            ((List <ImageModel>)item.Enterprise.Images).Add(new ImageModel(customImage));
                        }
                    }

                    if (item.CMImage != null)
                    {
                        item.Enterprise.ListItemImage = new ImageModel(item.CMImage);
                    }

                    if (item.HCMImage != null)
                    {
                        item.Enterprise.ListItemImage = new ImageModel(item.HCMImage);
                    }

                    if (item.ECMImage != null)
                    {
                        item.Enterprise.ListItemImage = new ImageModel(item.ECMImage);
                    }

                    ((List <ImageModel>)item.Enterprise.Images).Insert(0, item.Enterprise.ListItemImage);

                    item.Enterprise.Description = Localization.GetLocalizedText(item.Enterprise.LocalDescription,
                                                                                item.Enterprise.LocalDescriptionXml, item.Enterprise.LocalDescriptionLanguage, nativeLanguage);
                    item.Enterprise.EnterpriseLocations.ForEach(
                        el => el.Hours = Localization.GetLocalizedText(el.LocalHours, el.LocalHoursXml, el.LocalHoursLanguage, nativeLanguage));

                    enterprise = item.Enterprise;
                }
            }

            return(enterprise);
        }
Beispiel #7
0
        public List <EnterpriseModel> GetSearchEnterprises(int deviceId, float?hotelLatitude, float?hotelLongitude, float radiusInMeters,
                                                           int?categoryId, string text, EnterpriseSearchSortTypes sortType)
        {
            List <EnterpriseModel> enterprises = null;

            var device = RootRepository.DeviceRepository.GetDevice(deviceId);

            var hotelPoint = GeographyUtils.GetPointFromLatitudeAndLongitude(hotelLatitude, hotelLongitude);

            if (hotelPoint != null)
            {
                RootRepository.SecurityRepository.AssertDevicePermissions(deviceId);

                if (text != null)
                {
                    text = text.Trim();
                }

                var query = (from e in ProxylessContext.Enterprises
                             .Include(x => x.EnterpriseLocations.Select(el => el.BlackListEnterpriseLocationMaps))
                             .Include(x => x.EnterpriseLocations.Select(el => el.HotelBestOfEnterpriseLocationMaps))
                             .Include(x => x.EnterpriseCategoryMaps.Select(ecm => ecm.Image))
                             .Include(x => x.EnterpriseCategoryMaps.Select(ecm => ecm.CategoryMap.Image))
                             .Include(x => x.EnterpriseCategoryMaps.Select(ecm => ecm.CategoryMap.HotelCategoryMaps.Select(hcm => hcm.Image)))
                             .Include(
                                 x =>
                                 x.EnterpriseCategoryMaps.Select(
                                     ecm => ecm.HotelBestOfEnterpriseMaps.Select(hboem => hboem.HotelBestOfEnterpriseLocationMaps)))
                             .Include(x => x.BlackListEnterpriseMaps)
                             where
                             e.IsActive &&
                             e.EnterpriseLocations.Any(x => x.IsActive && x.Latitude != null && x.Longitude != null)
                             select new
                {
                    CMImage = e.EnterpriseCategoryMaps.FirstOrDefault().CategoryMap.Image,
                    ECMImage = e.EnterpriseCategoryMaps.FirstOrDefault().Image,
                    Enterprise = new EnterpriseModel
                    {
                        Blacklisted = e.BlackListEnterpriseMaps.Any(x => x.FKDevice == deviceId),
                        EnterpriseLocations = e.EnterpriseLocations.Where(x => x.IsActive && x.Latitude != null && x.Longitude != null).Select(el => new EnterpriseLocationModel
                        {
                            BingId = el.BingId,
                            Blacklisted = el.BlackListEnterpriseLocationMaps.Any(x => x.FKHotel == device.FKHotel),
                            DistanceInMeters = el.Coordinates.Distance(hotelPoint),
                            Location = new LocationModel
                            {
                                Address1 = el.Address1,
                                Address2 = el.Address2,
                                City = el.City,
                                ISOCountryCode = el.Country,
                                Latitude = el.Latitude,
                                Longitude = el.Longitude,
                                PostalCode = el.PostalCode,
                                ISOStateCode = el.State
                            },
                            Phone = el.Phone,
                            PKID = el.PKID,
                            Recommended = el.HotelBestOfEnterpriseLocationMaps.Any(x => x.HotelBestOfEnterpriseMap.FKDevice == deviceId)
                        }),
                        Name = e.Name,
                        PKID = e.PKID,
                        Recommended =
                            e.EnterpriseCategoryMaps.Any(x => x.HotelBestOfEnterpriseMaps.Any(hboem => hboem.FKDevice == deviceId))
                    },
                    e.EnterpriseCategoryMaps,
                    HCMImage =
                        e.EnterpriseCategoryMaps.FirstOrDefault()
                        .CategoryMap.HotelCategoryMaps.FirstOrDefault(x => x.FKDevice == deviceId)
                        .Image,
                });

                //var query = ( from e in ProxylessContext.Enterprises.Where( e2 => e2.IsActive )
                //			  let el = e.EnterpriseLocations.Where( el => el.IsActive && el.Coordinates.Distance( hotelPoint ) < radiusInMeters )
                //			  let ecm = e.EnterpriseCategoryMaps.Where( ecm2 => ecm2.IsActive )
                //			  let fecm = ecm.FirstOrDefault()
                //			  let cm = ecm.Where( ecm2 => ecm2.CategoryMap.IsActive ).Select( ecm2 => ecm2.CategoryMap )
                //			  let fcm = cm.FirstOrDefault()
                //			  let hcm = cm.SelectMany( cm2 => cm2.HotelCategoryMaps.Where( hcm2 => hcm2.IsActive && hcm2.FKDevice == deviceId ) )
                //			  let fhcm = hcm.OrderBy( hcm2 => hcm2.Ordinal ).FirstOrDefault()
                //			  let hboem = ecm.SelectMany( ecm2 => ecm2.HotelBestOfEnterpriseMaps.Where( hboem2 => hboem2.IsActive && hboem2.FKDevice == deviceId ).OrderBy( hboem2 => hboem2.Ordinal ) )
                //			  let hboelm = hboem.SelectMany( hboem2 => hboem2.HotelBestOfEnterpriseLocationMaps )
                //			  let blem = e.BlackListEnterpriseMaps.Where( blem2 => blem2.IsActive && blem2.FKDevice == deviceId )
                //			  let blelm = el.SelectMany( el2 => el2.BlackListEnterpriseLocationMaps.Where( blelm2 => blelm2.IsActive == true && blelm2.Hotel.Devices.Any( d => d.PKID == deviceId ) ) )
                //			  where el.Any()
                //			  select new
                //			  {
                //				  CMImage = fcm.Image,
                //				  ECMImage = fecm.Image,
                //				  Enterprise = new EnterpriseModel()
                //				  {
                //					  Blacklisted = blem.Any(),
                //					  EnterpriseLocations = ( from el2 in el
                //											  select new EnterpriseLocationModel()
                //											  {
                //												  BingId = el2.BingId,
                //												  Blacklisted = blelm.Select( blelm2 => blelm2.FKEnterpriseLocation ).Contains( el2.PKID ),
                //												  DistanceInMiles = ProxylessContext.CalculateDistance( el2.Latitude, el2.Longitude, hotelGeocode.Latitude.Value, hotelGeocode.Longitude.Value ),
                //												  Location = new LocationModel()
                //												  {
                //													  Address1 = el2.Address1,
                //													  Address2 = el2.Address2,
                //													  City = el2.City,
                //													  Country = new CountryModel
                //													  {
                //														  ISOCountryCode = el2.Country
                //													  },
                //													  Geocode = new GeocodeModel()
                //													  {
                //														  Latitude = el2.Latitude,
                //														  Longitude = el2.Longitude
                //													  },
                //													  PostalCode = el2.PostalCode,
                //													  State = new StateModel
                //													  {
                //														  ISOStateCode = el2.State,
                //													  }
                //												  },
                //												  Phone = el2.Phone,
                //												  PKID = el2.PKID,
                //												  Recommended = hboelm.Any( hboelm2 => hboelm2.FKEnterpriseLocation == el2.PKID )
                //											  } ),
                //					  Name = e.Name,
                //					  PKID = e.PKID,
                //					  Recommended = hboem.Any() && !hboelm.Any()
                //				  },
                //				  EnterpriseCategoryMaps = ecm,
                //				  HCMImage = fhcm.Image,
                //			  } );

                if (categoryId.HasValue)
                {
                    query = (from q in query
                             where q.EnterpriseCategoryMaps.Any(ecm2 => ecm2.CategoryMap.FKChildCategory == categoryId.Value)
                             select q);
                }

                if (!string.IsNullOrWhiteSpace(text))
                {
                    var ft = ProxylessContext.GetEnterprisesByFreeText(text).Select(gebft => gebft.Key);
                    query = query.Where(x => ft.Contains(x.Enterprise.PKID));
                }

                switch (sortType)
                {
                case EnterpriseSearchSortTypes.ALAPHABETICAL:
                    query = (from q in query
                             orderby q.Enterprise.Name
                             select q);

                    break;

                case EnterpriseSearchSortTypes.NEAREST:
                    query = (from q in query
                             orderby q.Enterprise.EnterpriseLocations.Min(el => el.DistanceInMeters),
                             q.Enterprise.Name
                             select q);

                    break;
                }

                var list = Rp.ExecuteAction(() => query.Take(20)).ToList();

                if (list != null)
                {
                    list.ForEach(e =>
                    {
                        if (e.Enterprise != null)
                        {
                            if (e.CMImage != null)
                            {
                                e.Enterprise.ListItemImage = new ImageModel(e.CMImage);
                            }

                            if (e.HCMImage != null)
                            {
                                e.Enterprise.ListItemImage = new ImageModel(e.HCMImage);
                            }

                            if (e.ECMImage != null)
                            {
                                e.Enterprise.ListItemImage = new ImageModel(e.ECMImage);
                            }

                            if (enterprises == null)
                            {
                                enterprises = new List <EnterpriseModel>();
                            }

                            enterprises.Add(e.Enterprise);
                        }
                    });
                }
            }

            return(enterprises);
        }