private FulfillmentSchedule BuildScheduleWithOpeningHourExceptions(DateTime startDate, DateTime endDate,
                                                                           bool isRecurrent, DayOfWeek dayOfWeek)
        {
            var schedule = new FulfillmentSchedule
            {
                OpeningHourExceptions = new List <DailyScheduleException>
                {
                    new DailyScheduleException
                    {
                        IsClosed    = true,
                        IsRecurrent = isRecurrent,
                        StartDate   = startDate,
                        EndDate     = endDate
                    }
                },
                OpeningHours = new List <DailySchedule>
                {
                    new DailySchedule
                    {
                        Day            = dayOfWeek,
                        IsClosed       = false,
                        IsOpenedAllDay = true
                    }
                }
            };

            return(schedule);
        }
 protected virtual List <DailyScheduleViewModel> GetOpeningHours(FulfillmentSchedule schedule, CultureInfo cultureInfo, DateTime today)
 {
     return(schedule.OpeningHours.Select(oh =>
                                         new DailyScheduleViewModel
     {
         LocalizedDay = GetStoreOpenHoursLocalizedDayName(oh.Day, cultureInfo),
         IsDayToday = oh.Day == today.DayOfWeek,
         IsClosed = oh.IsClosed,
         IsOpenedAllDay = oh.IsOpenedAllDay,
         OpeningTimes = oh.OpeningTimes.Select(ot => GetScheduleIntervalViewModel(ot, cultureInfo)).ToList()
     }
                                         ).ToList());
 }
        public virtual IEnumerable <ScheduleInterval> GetOpeningTimes(FulfillmentSchedule schedule, DateTime dateTime)
        {
            var openingHourExceptions = schedule.OpeningHourExceptions.Where(dse =>
                                                                             dse.IsRecurrent
                    ? IsDateInRecurrentRange(dateTime, dse.StartDate, dse.EndDate)
                    : IsDateInRange(dateTime, dse.StartDate, dse.EndDate)
                                                                             ).ToList();

            if (openingHourExceptions.Any(ohe => ohe.IsClosed))
            {
                yield break;
            }
            if (openingHourExceptions.Any())
            {
                foreach (var openHourException in openingHourExceptions)
                {
                    yield return(openHourException.OpeningTime);
                }
                yield break;
            }

            // Scheduler
            foreach (var openHours in schedule.OpeningHours.Where(oh => oh.Day == dateTime.DayOfWeek))
            {
                if (openHours.IsOpenedAllDay)
                {
                    yield return(new ScheduleInterval()
                    {
                        BeginingTime = TimeSpan.Zero,
                        EndingTime = TimeSpan.FromDays(1)
                    });

                    yield break;
                }
                if (openHours.IsClosed)
                {
                    yield break;
                }
                foreach (var openingTime in openHours.OpeningTimes)
                {
                    yield return(openingTime);
                }
            }
        }
示例#4
0
        private FulfillmentSchedule BuildSchedule(DateTime startDate, DateTime endDate,
                                                  bool isRecurrent, bool isClosed)
        {
            var schedule = new FulfillmentSchedule
            {
                OpeningHourExceptions = new List <DailyScheduleException>
                {
                    new DailyScheduleException
                    {
                        IsClosed    = isClosed,
                        IsRecurrent = isRecurrent,
                        StartDate   = startDate,
                        EndDate     = endDate
                    }
                }
            };

            return(schedule);
        }
        private FulfillmentSchedule BuildSchedule(List <ScheduleInterval> openingTimes = null, bool isClosed = false,
                                                  bool isOpenedAllDay = true)
        {
            var schedule = new FulfillmentSchedule
            {
                OpeningHours = new List <DailySchedule>
                {
                    new DailySchedule
                    {
                        Day            = DateTime.Today.DayOfWeek,
                        IsClosed       = isClosed,
                        OpeningTimes   = openingTimes,
                        IsOpenedAllDay = isOpenedAllDay
                    }
                }
            };

            return(schedule);
        }
        public virtual IEnumerable <DailyScheduleException> GetOpeningHourExceptions(FulfillmentSchedule schedule,
                                                                                     DateTime dateTime,
                                                                                     int periodInYears = 1)
        {
            var exceptions = schedule.OpeningHourExceptions
                             .Where(
                ex => ex.IsRecurrent
                        ? ex.StartDate.DayOfYear >= dateTime.DayOfYear
                        : IsDateInRange(ex.StartDate, dateTime, dateTime.AddYears(periodInYears)))
                             .OrderBy(ex => ex.StartDate.DayOfYear);

            foreach (var ex in exceptions)
            {
                if (ex.IsRecurrent)
                {
                    var dateNow = DateTime.Now;
                    ex.StartDate = new DateTime(dateNow.Year, ex.StartDate.Month, ex.StartDate.Day);
                    ex.EndDate   = new DateTime(dateNow.Year, ex.EndDate.Month, ex.EndDate.Day);
                }
            }
            return(exceptions.OrderBy(ex => ex.StartDate.Year));
        }
        protected virtual List <DailyScheduleExceptionViewModel> GetOpeningHourExceptions(FulfillmentSchedule schedule, CultureInfo cultureInfo, DateTime today)
        {
            var exceptions = StoreScheduleProvider.GetOpeningHourExceptions(schedule, today, 1);

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