Exemplo n.º 1
0
        public ScheduleViewModel(Schedule schedule, WellknownData wellknown)
        {
            Weeks = schedule.Weeks.OrderBy(x => x.WeekNumber).Select(x => new ScheduleWeekViewModel(x, wellknown)).ToList();
            if (Weeks.Count > 1)
            {
                for (int i = 0; i < Weeks.Count - 1; i++)
                {
                    int insertCount = Weeks[i + 1].WeekNumber - Weeks[i].WeekNumber - 1;
                    for (int j = 0; j < insertCount; j++)
                    {
                        ScheduleWeekViewModel emptyWeek = new ScheduleWeekViewModel(new ScheduleWeek(Weeks[i].WeekNumber + j + 1), wellknown);
                        Weeks.Insert(i + j + 1, emptyWeek);
                    }
                    i += insertCount;
                }
            }
            int daysSinceTermStart = (int)(DateTimeOffset.Now.Date - wellknown.TermStartDate).TotalDays;
            int weekNumber         = daysSinceTermStart / 7;

            if (weekNumber < 0 || weekNumber >= Weeks.Count)
            {
                Today = new List <ScheduleEntryViewModel>();
            }
            else
            {
                int todayDayOfWeek = (int)DateTimeOffset.Now.DayOfWeek;
                todayDayOfWeek = todayDayOfWeek == 0 ? 7 : todayDayOfWeek;
                ScheduleDayViewModel day = Weeks[weekNumber].Days[todayDayOfWeek - 1];
                Today = day.Entries.Where(x => x.LocalEndTime > DateTimeOffset.Now).ToList() ?? new List <ScheduleEntryViewModel>();
            }
        }
Exemplo n.º 2
0
        public ScheduleWeekViewModel(ScheduleWeek week, WellknownData wellknown)
        {
            WeekNumber        = week.WeekNumber;
            WeekNumberDisplay = Application.Current.GetService <ILocalizationService>().Format("ScheduleTableWeekNumberHeaderFormat", week.WeekNumber);
            Days = new ScheduleDayViewModel[7];
            DateTimeOffset weekStartDate = wellknown.TermStartDate.GetLocalDate().AddDays((week.WeekNumber - 1) * 7);

            foreach (var group in week.Entries.GroupBy(x => x.DayOfWeek))
            {
                int            dayOfWeek = group.Key;
                DateTimeOffset day       = weekStartDate.AddDays(dayOfWeek - 1);
                Days[dayOfWeek - 1] = new ScheduleDayViewModel(WeekNumber, day, group, wellknown);
            }
            for (int i = 0; i < 7; i++)
            {
                if (!Days[i].Initialized)
                {
                    DateTimeOffset day = weekStartDate.AddDays(i);
                    Days[i] = new ScheduleDayViewModel(WeekNumber, day, Array.Empty <ScheduleEntry>(), wellknown);
                }
            }
        }