示例#1
0
        public IEnumerable <DayWorkloadDto> GetWeekWorkload(DateTime weekStartDate)
        {
            StudioSchedule schedule      = _costEvaluationService.GetSchedule();
            int            scheduleStart = schedule.Start;
            int            scheduleEnd   = schedule.End;

            weekStartDate = weekStartDate.Date;
            DateTime weekEndDate = weekStartDate.AddDays(7);

            var bookings = GetBookingsForPeriod(weekStartDate, weekEndDate)
                           .Select(x => new { x.From, x.To })
                           .ToList();

            var list = new List <DayWorkloadDto>();

            for (DateTime i = weekStartDate; i < weekEndDate; i = i.AddDays(1))
            {
                var dayWorkload = new DayWorkloadDto
                {
                    Date      = i,
                    FreeHours = Enumerable
                                .Range(scheduleStart, scheduleEnd - scheduleStart + 1)
                                .Select(x => i.AddHours(x))
                                .Where(x => bookings
                                       .All(y => x < y.From || x >= y.To))
                                .Select(x => x.Hour)
                                .ToArray()
                };
                list.Add(dayWorkload);
            }
            return(list);
        }
示例#2
0
        public IEnumerable <DayHourDto> GetDayWorkload(DateTime date)
        {
            StudioSchedule schedule      = _costEvaluationService.GetSchedule();
            int            scheduleStart = schedule.Start;
            int            scheduleEnd   = schedule.End;
            var            dateStart     = date.Date;
            var            dateEnd       = dateStart.AddDays(1);

            var bookings = GetBookingsForPeriod(dateStart, dateEnd)
                           .Select(x => new { x.From, x.To })
                           .ToList();

            List <DayHourDto> list = Enumerable
                                     .Range(scheduleStart, scheduleEnd - scheduleStart + 1)
                                     .Select(x => dateStart.AddHours(x))
                                     .Select(x => new DayHourDto
            {
                Hour      = x.Hour,
                Available = bookings.All(y => x < y.From || x >= y.To)
            })
                                     .ToList();

            return(list);
        }
示例#3
0
        public BookingCostDto EvaluateBookingCost(DateTime from, DateTime to, string promoCode)
        {
            StudioSchedule   schedule      = EvaluateStudioSchedule();
            PromoCodeInfoDto promoCodeInfo = EvaluatePromoCodeInfo(promoCode);

            var result = new BookingCostDto
            {
                PromoCode = promoCodeInfo
            };

            schedule.Cost *= promoCodeInfo.CostModifier;
            foreach (var scheduleSpecialCost in schedule.SpecialCosts)
            {
                scheduleSpecialCost.Cost *= promoCodeInfo.CostModifier;
            }

            if (schedule.SpecialCosts == null || schedule.SpecialCosts.Length == 0)
            {
                return(SetupIntervals(result, new[] { CreateIntervalCost(from, to, schedule.Cost) }));
            }

            ICollection <IntervalCostDto> intervalCosts = new Collection <IntervalCostDto>();
            ICollection <Interval>        intervals     = ParseToIntervals(from, to);

            foreach (var interval in intervals)
            {
                var specialCosts = schedule.SpecialCosts
                                   .Where(x => x.DayType.HasFlag(interval.DayType))
                                   .Select(x => new
                {
                    From = interval.From.Date.AddHours(x.Start),
                    To   = interval.From.Date.AddHours(x.End + 1),
                    x.Cost
                })
                                   .OrderBy(x => x.From);

                DateTime intervalStart = interval.From;
                foreach (var specialCost in specialCosts)
                {
                    if (intervalStart >= specialCost.To)
                    {
                        continue;
                    }

                    if (interval.To <= specialCost.From)
                    {
                        intervalCosts.Add(CreateIntervalCost(intervalStart, interval.To, schedule.Cost));
                        intervalStart = interval.To;
                        break;
                    }

                    if (intervalStart < specialCost.From)
                    {
                        intervalCosts.Add(CreateIntervalCost(intervalStart, specialCost.From, schedule.Cost));
                        intervalStart = specialCost.From;
                    }

                    if (interval.To <= specialCost.To)
                    {
                        intervalCosts.Add(CreateIntervalCost(intervalStart, interval.To, specialCost.Cost));
                        intervalStart = interval.To;
                        break;
                    }
                    else
                    {
                        intervalCosts.Add(CreateIntervalCost(intervalStart, specialCost.To, specialCost.Cost));
                        intervalStart = specialCost.To;
                    }
                }

                if (intervalStart < interval.To)
                {
                    intervalCosts.Add(CreateIntervalCost(intervalStart, interval.To, schedule.Cost));
                }
            }

            return(SetupIntervals(result, intervalCosts));
        }