コード例 #1
0
        protected virtual StoreScheduleViewModel CreateStoreScheduleViewModel(CreateStoreViewModelParam param)
        {
            if (param.Store.StoreSchedule == null)
            {
                return(null);
            }

            var model        = new StoreScheduleViewModel();
            var storeNowTime = DateTime.Now;

            if (!string.IsNullOrWhiteSpace(param.Store.FulfillmentLocation.TimeZone))
            {
                var storeTimeInfo = TimeZoneInfo.FindSystemTimeZoneById(param.Store.FulfillmentLocation.TimeZone);
                storeNowTime = TimeZoneInfo.ConvertTime(DateTime.UtcNow, storeTimeInfo);
            }

            model.OpeningHours          = GetOpeningHours(param, storeNowTime);
            model.OpeningHourExceptions = GetOpeningHourExceptions(param, storeNowTime);

            var todayOpeningTimes =
                StoreScheduleProvider.GetOpeningTimes(param.Store.StoreSchedule, storeNowTime).ToList();

            model.TodayOpeningTimes = todayOpeningTimes.Select(ot => GetScheduleIntervalViewModel(ot, param.CultureInfo)).ToList();

            model.IsOpenNow = IsTimeInIntervals(storeNowTime.TimeOfDay, todayOpeningTimes);

            return(model);
        }
コード例 #2
0
        public virtual StoreViewModel CreateStoreViewModel(CreateStoreViewModelParam param)
        {
            var store          = param.Store;
            var storeViewModel = ViewModelMapper.MapTo <StoreViewModel>(store, param.CultureInfo);

            storeViewModel.Address = CreateStoreAddressViewModel(param);
            storeViewModel.LocalizedDisplayName  = GetStoreLocalizedDisplayName(storeViewModel, param.CultureInfo);
            storeViewModel.FulfillmentLocationId = store.FulfillmentLocation.Id;
            storeViewModel.GoogleDirectionsLink  = GetGoogleDirectionsLink(storeViewModel.Address);
            storeViewModel.GoogleStaticMapUrl    = GetGoogleStaticMapUrl(storeViewModel.Address);

            storeViewModel.Url = StoreUrlProvider.GetStoreUrl(new GetStoreUrlParam()
            {
                BaseUrl     = param.BaseUrl,
                CultureInfo = param.CultureInfo,
                StoreNumber = store.Number,
                StoreName   = storeViewModel.Name
            });

            if (param.SearchPoint != null && storeViewModel.Address.Latitude != null &&
                storeViewModel.Address.Longitude != null)
            {
                storeViewModel.DestinationToSearchPoint = Math.Round(GeoCodeCalculator.CalcDistance(
                                                                         storeViewModel.Address.Latitude.Value, storeViewModel.Address.Longitude.Value,
                                                                         param.SearchPoint.Lat, param.SearchPoint.Lng, EarthRadiusMeasurement.Kilometers), 2);
            }

            storeViewModel.Schedule = CreateStoreScheduleViewModel(param);

            return(storeViewModel);
        }
コード例 #3
0
 protected virtual List <DailyScheduleViewModel> GetOpeningHours(CreateStoreViewModelParam param, DateTime today)
 {
     return(param.Store.StoreSchedule.OpeningHours.Select(oh =>
                                                          new DailyScheduleViewModel
     {
         LocalizedDay = GetStoreOpenHoursLocalizedDayName(oh.Day, param.CultureInfo),
         IsDayToday = oh.Day == today.DayOfWeek,
         IsClosed = oh.IsClosed,
         IsOpenedAllDay = oh.IsOpenedAllDay,
         OpeningTimes = oh.OpeningTimes.Select(ot => GetScheduleIntervalViewModel(ot, param.CultureInfo)).ToList()
     }
                                                          ).ToList());
 }
コード例 #4
0
        public virtual async Task <StoreViewModel> GetStoreViewModelAsync(GetStoreParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param");
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentNullException("scope");
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentNullException("cultureInfo");
            }
            if (string.IsNullOrWhiteSpace(param.StoreNumber))
            {
                throw new ArgumentNullException("storeNumber");
            }
            if (string.IsNullOrWhiteSpace(param.BaseUrl))
            {
                throw new ArgumentNullException("baseUrl");
            }

            var overtureStore = await StoreRepository.GetStoreByNumberAsync(param).ConfigureAwait(false);

            if (overtureStore == null)
            {
                return(null);
            }

            var createVmParam = new CreateStoreViewModelParam
            {
                Store       = overtureStore,
                CultureInfo = param.CultureInfo,
                BaseUrl     = param.BaseUrl,
                SearchPoint = param.SearchPoint
            };
            var storeViewModel = StoreViewModelFactory.CreateStoreViewModel(createVmParam);

            storeViewModel.StructuredData = StoreViewModelFactory.CreateStoreStructuredDataViewModel(createVmParam);

            if (storeViewModel.HasLocation())
            {
                storeViewModel.Context.Add("latitude", storeViewModel.GetLatitude().ToString(CultureInfo.InvariantCulture));
                storeViewModel.Context.Add("longitude", storeViewModel.GetLongitude().ToString(CultureInfo.InvariantCulture));
            }

            return(storeViewModel);
        }
コード例 #5
0
        protected virtual StoreAddressViewModel CreateStoreAddressViewModel(CreateStoreViewModelParam param)
        {
            var addressViewModel = new StoreAddressViewModel();

            if (param.Store.FulfillmentLocation != null && param.Store.FulfillmentLocation.Addresses != null)
            {
                var overtureAddress = param.Store.FulfillmentLocation.Addresses.FirstOrDefault();
                if (overtureAddress != null)
                {
                    addressViewModel = ViewModelMapper.MapTo <StoreAddressViewModel>(overtureAddress, param.CultureInfo);

                    addressViewModel.PhoneNumber = GetFormattedAddressPhoneNumber(overtureAddress.PhoneNumber,
                                                                                  param.CultureInfo);

                    if (!string.IsNullOrWhiteSpace(overtureAddress.CountryCode))
                    {
                        var countryName = CountryService.RetrieveCountryDisplayNameAsync(new RetrieveCountryParam
                        {
                            CultureInfo = param.CultureInfo,
                            IsoCode     = overtureAddress.CountryCode
                        }).Result;


                        var regionName =
                            CountryService.RetrieveRegionDisplayNameAsync(new RetrieveRegionDisplayNameParam
                        {
                            CultureInfo = param.CultureInfo,
                            IsoCode     = overtureAddress.CountryCode,
                            RegionCode  = overtureAddress.RegionCode
                        }).Result;

                        addressViewModel.CountryName = !string.IsNullOrWhiteSpace(countryName)
                            ? countryName
                            : overtureAddress.CountryCode.ToUpper();
                        addressViewModel.RegionName = !string.IsNullOrWhiteSpace(regionName)
                            ? regionName
                            : overtureAddress.RegionCode;
                    }
                }
            }

            return(addressViewModel);
        }
コード例 #6
0
        public virtual StoreViewModel CreateStoreViewModel(CreateStoreViewModelParam param)
        {
            var store          = param.Store;
            var storeViewModel = ViewModelMapper.MapTo <StoreViewModel>(store, param.CultureInfo);

            storeViewModel.Address = CreateStoreAddressViewModel(param);
            storeViewModel.LocalizedDisplayName  = GetStoreLocalizedDisplayName(storeViewModel, param.CultureInfo);
            storeViewModel.FulfillmentLocationId = store.FulfillmentLocation.Id;
            storeViewModel.GoogleDirectionsLink  = GetGoogleDirectionsLink(storeViewModel.Address);
            storeViewModel.GoogleStaticMapUrl    = GetGoogleStaticMapUrl(storeViewModel.Address);

            storeViewModel.Url = StoreUrlProvider.GetStoreUrl(new GetStoreUrlParam()
            {
                BaseUrl     = param.BaseUrl,
                CultureInfo = param.CultureInfo,
                StoreNumber = store.Number,
                StoreName   = storeViewModel.Name
            });

            if (param.SearchPoint != null && storeViewModel.Address.Latitude != null &&
                storeViewModel.Address.Longitude != null)
            {
                double earthRadius = GoogleMaps.GoogleMapsSettings.LengthMeasureUnit == Enums.LengthMeasureUnitEnum.km ? EarthRadiusMeasurement.Kilometers : EarthRadiusMeasurement.Miles;
                storeViewModel.DestinationToSearchPoint = Math.Round(GeoCodeCalculator.CalcDistance(
                                                                         storeViewModel.Address.Latitude.Value, storeViewModel.Address.Longitude.Value,
                                                                         param.SearchPoint.Lat, param.SearchPoint.Lng, earthRadius), 2);

                storeViewModel.LengthMeasureUnit = GoogleMaps.GoogleMapsSettings.LengthMeasureUnit.ToString();
            }

            storeViewModel.Schedule = CreateStoreScheduleViewModel(param);

            if (param.Store.FulfillmentLocation != null)
            {
                storeViewModel.SupportDelivery     = param.Store.FulfillmentLocation.SupportDelivery;
                storeViewModel.SupportPickUp       = param.Store.FulfillmentLocation.SupportPickUp;
                storeViewModel.InventoryLocationId = param.Store.FulfillmentLocation.InventoryLocationId;
            }

            return(storeViewModel);
        }
コード例 #7
0
        public virtual StoreStructuredDataViewModel CreateStoreStructuredDataViewModel(CreateStoreViewModelParam param)
        {
            var store = param.Store;
            var model = new StoreStructuredDataViewModel
            {
                Name      = store.Name,
                Telephone = store.PhoneNumber,
                Url       = StoreUrlProvider.GetStoreUrl(new GetStoreUrlParam()
                {
                    BaseUrl     = param.BaseUrl,
                    CultureInfo = param.CultureInfo,
                    StoreNumber = store.Number,
                    StoreName   = store.Name
                })
            };
            var address = store.FulfillmentLocation?.Addresses?.FirstOrDefault();

            if (address != null)
            {
                model.StreetAddress   = address.Line1;
                model.AddressLocality = address.City;
                model.AddressRegion   = address.RegionCode;
                model.AddressCountry  = address.CountryCode;
                model.PostalCode      = address.PostalCode;
                model.Longitude       = address.Longitude;
                model.Latitude        = address.Latitude;
                if (string.IsNullOrWhiteSpace(model.Telephone))
                {
                    model.Telephone = address.PhoneNumber;
                }
            }

            if (store.StoreSchedule != null)
            {
                //// fixed datetime formats based on https://developers.google.com/structured-data/local-businesses/
                var dataTimeFormat = @"hh\:mm\:ss";
                var dateFormat     = @"yyyy-MM-dd";
                model.OpeningHoursSpecifications = new List <StructuredDataOpeningHoursSpecificationViewModel>();
                var groups = store.StoreSchedule.OpeningHours
                             .Where(it => !it.IsClosed)
                             .GroupBy(
                    x =>
                    new
                {
                    x.OpeningTimes.FirstOrDefault()?.BeginingTime,
                    x.OpeningTimes.FirstOrDefault()?.EndingTime
                });
                foreach (var group in groups)
                {
                    var opens        = group.Key.BeginingTime ?? DateTime.Today.TimeOfDay;
                    var closes       = group.Key.EndingTime ?? DateTime.Today.AddTicks(-1).AddDays(1).TimeOfDay;
                    var openHourSpec = new StructuredDataOpeningHoursSpecificationViewModel
                    {
                        Opens      = opens.ToString(dataTimeFormat),
                        Closes     = closes.ToString(dataTimeFormat),
                        DayOfWeeks = new List <DayOfWeek>()
                    };
                    foreach (var item in group)
                    {
                        openHourSpec.DayOfWeeks.Add(item.Day);
                    }
                    model.OpeningHoursSpecifications.Add(openHourSpec);
                }

                var exceptions = StoreScheduleProvider.GetOpeningHourExceptions(store.StoreSchedule, DateTime.Today, 1);
                foreach (var item in exceptions)
                {
                    var opens        = item.IsClosed ? DateTime.Today.TimeOfDay : item.OpeningTime.BeginingTime;
                    var closes       = item.IsClosed ? DateTime.Today.AddSeconds(1).TimeOfDay : item.OpeningTime.EndingTime;
                    var openHourSpec = new StructuredDataOpeningHoursSpecificationViewModel
                    {
                        ValidFrom    = item.StartDate.ToString(dateFormat),
                        ValidThrough = item.EndDate.ToString(dateFormat),
                        Opens        = opens.ToString(dataTimeFormat),
                        Closes       = closes.ToString(dataTimeFormat),
                    };
                    model.OpeningHoursSpecifications.Add(openHourSpec);
                }
            }
            return(model);
        }
コード例 #8
0
        protected virtual List <DailyScheduleExceptionViewModel> GetOpeningHourExceptions(CreateStoreViewModelParam param, DateTime today)
        {
            var exceptions = StoreScheduleProvider.GetOpeningHourExceptions(param.Store.StoreSchedule, today, 1);

            return(exceptions.Select(
                       ex => ViewModelMapper.MapTo <DailyScheduleExceptionViewModel>(new
            {
                ex.StartDate,
                ex.EndDate,
                ex.IsClosed,
                OpeningTime = GetScheduleIntervalViewModel(ex.OpeningTime, param.CultureInfo)
            }, param.CultureInfo))
                   .ToList());
        }