public ManageLessonsPage(SavedGroup group) { InitializeComponent(); Title += $": {group.Name}"; this.group = group; EventList eventList = EventsDataStore.GetEventsLocal(group.ID); if (eventList == null) { return; } List <LessonSettings> lessonSettings = LessonSettingsDataStore.GetLessonSettings(group.ID); lessons = new ObservableCollection <LessonSettings> ( eventList.Lessons() .Select(lesson => { LessonSettings res = lessonSettings.FirstOrDefault(ls => ls.LessonName == lesson) ?? new LessonSettings { LessonName = lesson }; res.EventTypes = eventList.EventTypes(lesson).ToList(); return(res); }) .OrderBy(lesson => lesson.LessonName) ); LessonsList.ItemsSource = lessons; if (lessons.Count == 0) { NoSourceLayout.IsVisible = true; } MessagingCenter.Subscribe <LessonSettingsPage, LessonSettings>(this, "OneLessonSettingsChanged", (sender, newLessonSettings) => { for (int i = 0; i < lessons.Count; i++) { if (lessons[i].LessonName == newLessonSettings.LessonName) { lessons[i] = newLessonSettings; lessons[i].NotifyChanged(); break; } } }); }
private async Task UpdateTimetable(params SavedGroup[] savedGroups) { if (savedGroups == null || savedGroups.Length == 0 || CheckUpdateTimetableRights() == false) { return; } GroupsLayout.IsEnabled = false; ProgressLayout.IsVisible = true; await Task.Factory.StartNew(() => { string result; if (EventsDataStore.GetEventsFromCist(Config.TimetableFromDate, Config.TimetableToDate, savedGroups) != null) { foreach (SavedGroup group in savedGroups) { group.LastUpdated = DateTime.Now; } GroupsDataStore.UpdateSaved(groups.ToList()); if (savedGroups.Length == 1) { result = $"Расписание группы {savedGroups[0].Name} успешно обновлено."; } else { result = $"Расписание успешно обновлено для групп:{Environment.NewLine}{string.Join(", ", savedGroups.Select(g => g.Name))}"; } } else { result = "Произошла ошибка, пожалуйста, попробуйте позже."; } Device.BeginInvokeOnMainThread(() => { DisplayAlert("Обновление расписания", result, "Ok"); ProgressLayout.IsVisible = false; GroupsLayout.IsEnabled = true; }); }); }