Exemple #1
0
        public override string ToString()
        {
            if (Items.Count == 0)
            {
                return("<empty>");
            }
            List <WorkingScheduleItemDto> items = new List <WorkingScheduleItemDto>();

            foreach (WorkingScheduleItemDto realItem in Items)
            {
                WorkingScheduleItemDto item = items.FirstOrDefault(i => i.StartTime == realItem.StartTime && i.EndTime == realItem.EndTime);
                if (item != null)
                {
                    item.WeekDay = item.WeekDay + "," + realItem.WeekDay.Substring(0, 3);
                }
                else
                {
                    items.Add(new WorkingScheduleItemDto()
                    {
                        StartTime = realItem.StartTime,
                        EndTime   = realItem.EndTime,
                        WeekDay   = realItem.WeekDay.Substring(0, 3),
                    });
                }
            }

            return(String.Join(";", items.Select(i => String.Format("{0} ({1}:{2}-{3}:{4})",
                                                                    i.WeekDay, i.StartTime.Hour, i.StartTime.Minute, i.EndTime.Hour, i.EndTime.Minute)).ToArray()));
        }
Exemple #2
0
 public bool DiffersFrom(WorkingScheduleItemDto item)
 {
     return(item.IsActive != IsActive ||
            item.StartTime != StartTime ||
            item.EndTime != EndTime ||
            item.BreakTo != BreakTo ||
            item.BreakFrom != BreakFrom ||
            item.ModalityId != ModalityId ||
            item.WeekDay != WeekDay);
 }
Exemple #3
0
 public WorkingScheduleItemDto(WorkingScheduleItemDto item)
 {
     Id         = item.Id;
     ModalityId = item.Id;
     WeekDay    = item.WeekDay;
     StartTime  = item.StartTime;
     EndTime    = item.EndTime;
     BreakFrom  = item.BreakFrom;
     BreakTo    = item.BreakTo;
     IsActive   = item.IsActive;
 }
Exemple #4
0
        public WorkingScheduleItemDto GetScheduleForDay(DateTime day)
        {
            WorkingScheduleItemDto sched = GetScheduleForHoliday(day);

            if (sched == null)
            {
                sched = GetScheduleForDay(day.DayOfWeek);
            }
            if (sched != null)
            {
                sched           = new WorkingScheduleItemDto(sched);
                sched.StartTime = day.Date + sched.StartTime.TimeOfDay;
                sched.EndTime   = day.Date + sched.EndTime.TimeOfDay;
            }
            return(sched);
        }
Exemple #5
0
        public bool Contains(WorkingScheduleItemDto schedule)
        {
            long smallStart = schedule.StartTime.Hour * 60 + schedule.StartTime.Minute;
            long smallEnd   = schedule.EndTime.Hour * 60 + schedule.EndTime.Minute;
            long start      = this.StartTime.Hour * 60 + this.StartTime.Minute;
            long end        = this.EndTime.Hour * 60 + this.EndTime.Minute;

            if (this.BreakFrom.HasValue && this.BreakTo.HasValue)
            {
                long breakStart = this.BreakFrom.Value.Hour * 60 + this.BreakFrom.Value.Minute;
                long breakEnd   = this.BreakTo.Value.Hour * 60 + this.BreakTo.Value.Minute;
                return((start <= smallStart && breakStart >= smallEnd) || (breakEnd <= smallStart && end >= smallEnd));;
            }
            else
            {
                return(start <= smallStart && end >= smallEnd);
            }
        }
Exemple #6
0
        public bool DiffersFrom(WorkingScheduleDto workingSchedule)
        {
            if (workingSchedule == null)
            {
                return(true);
            }
            if (workingSchedule.Items != null || this.Items != null)
            {
                if (workingSchedule.Items == null)
                {
                    return(true);
                }
                if (Items.Count != workingSchedule.Items.Count)
                {
                    return(true);
                }

                foreach (WorkingScheduleItemDto thisItem in Items)
                {
                    WorkingScheduleItemDto item = workingSchedule.GetScheduleForDay(thisItem.WeekDay);
                    if (item == null)
                    {
                        return(true);
                    }
                    if (item.DiffersFrom(thisItem))
                    {
                        return(true);
                    }
                }
            }
            if (this.Holidays.Count != workingSchedule.Holidays.Count)
            {
                return(true);
            }
            foreach (HolidayDto holiday in workingSchedule.Holidays)
            {
                if (!this.Holidays.Contains <HolidayDto>(holiday, HolidayComparer.Instance))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #7
0
        private WorkingScheduleItemDto GetScheduleForHoliday(DateTime day)
        {
            WorkingScheduleItemDto holiday = Items.FirstOrDefault(h => h.WeekDay == day.Date.ToString("yyyy-MM-dd"));

            return(holiday);
        }