示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Workday"/> class.
        /// </summary>
        /// <param name="startTime">The start time.</param>
        /// <param name="endTime">The end time.</param>
        /// <param name="duration">The duration.</param>
        public Workday(string startTime, string endTime, SlotDuration duration)
        {
            this.Duration = duration;
            this.From = this.GetTime(startTime);
            this.To = this.GetTime(endTime);

            if (this.From > this.To) throw new ArgumentException(Messages.Error_BeginBiggerThanEnd);
        }
示例#2
0
        private bool IsSlotOpen(Field field, DateTime day, TimeSpan time, SlotDuration duration)
        {
            var start = day.Add(time);
            var end = start.AddMinutes((int) duration);

            return !_context.Slots.Any(
                s =>
                s.Field.Id == field.Id &&
                ((s.StartDateTime <= start && s.EndDateTime > start) || (s.StartDateTime > start && s.StartDateTime < end)));
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Workday"/> class.
        /// </summary>
        /// <param name="startTime">The start time.</param>
        /// <param name="endTime">The end time.</param>
        /// <param name="duration">The duration.</param>
        public Workday(string startTime, string endTime, SlotDuration duration)
        {
            this.Duration = duration;
            this.From     = this.GetTime(startTime);
            this.To       = this.GetTime(endTime);

            if (this.From > this.To)
            {
                throw new ArgumentException(Messages.Error_BeginBiggerThanEnd);
            }
        }
示例#4
0
        private string Translate(SlotDuration slotDuration)
        {
            var value = string.Empty;

            switch (slotDuration)
            {
            case SlotDuration.ThirtyMinutes:
                value = Messages.SlotDuration_ThirtyMinutes;
                break;

            case SlotDuration.OneHour:
                value = Messages.SlotDuration_OneHour;
                break;

            default:
                Assert.FailOnEnumeration(slotDuration);
                break;
            }
            return(value);
        }
示例#5
0
        public void Create(Field field, 
            DayOfWeek dayOfWeek, 
            DateTime startDate, 
            DateTime endDate, 
            TimeSpan startTime, 
            TimeSpan endTime, 
            SlotDuration duration, 
            bool allowFriendlies,
            bool allowStateLeague,
            bool allowTraining)
        {
            var currentDay = startDate.Date;
            var endDay = endDate.Date;

            while (currentDay <= endDay)
            {
                TimeSpan currentTime = startTime;

                while (currentTime.Add(new TimeSpan(0, (int) duration, 0)) <= endTime)
                {
                    if (currentDay.DayOfWeek == dayOfWeek && IsSlotOpen(field, currentDay, currentTime, duration))
                    {
                        var slot = new Slot
                                       {
                                           Field = field,
                                           StartDateTime = currentDay.Add(currentTime),
                                           EndDateTime = currentDay.Add(currentTime).AddMinutes((int) duration),
                                           AllowedActivities = MapAllowedActivities(allowFriendlies, allowStateLeague, allowTraining)
                                       };

                        _context.Slots.Add(slot);
                    }
                    currentTime = currentTime.Add(new TimeSpan(0, (int) duration, 0));
                }

                currentDay = currentDay.AddDays(1);
            }

            _context.SaveChanges();
        }
        public static TimeSpan ToTimeSpan(this SlotDuration slot)
        {
            var      thirtyMinute = new TimeSpan(0, 30, 0);
            var      oneHour      = new TimeSpan(1, 0, 0);
            TimeSpan result       = new TimeSpan();

            switch (slot)
            {
            case SlotDuration.ThirtyMinutes:
                result = thirtyMinute;
                break;

            case SlotDuration.OneHour:
                result = oneHour;
                break;

            default:
                Assert.FailOnEnumeration(slot);
                break;
            }
            return(result);
        }
示例#7
0
        private string Translate(SlotDuration slotDuration)
        {
            var value = string.Empty;

            switch (slotDuration)
            {
                case SlotDuration.ThirtyMinutes:
                    value = Messages.SlotDuration_ThirtyMinutes;
                    break;
                case SlotDuration.OneHour:
                    value = Messages.SlotDuration_OneHour;
                    break;
                default:
                    Assert.FailOnEnumeration(slotDuration);
                    break;
            }
            return value;
        }