Пример #1
0
        protected async void LoadCourses()
        {
            LoadingCourses = true;
            bool useAll = App.isUsingAllCourses();
            //IsBusy = true;

            // Get the courses!
            L2PCourseInfoSetData courses;

            if (useAll)
            {
                courses = await api.RESTCalls.L2PViewAllCourseInfoAsync();
            }
            else
            {
                string semester;
                if (DateTime.Now.Month < 4)
                {
                    // winter semester but already in new year -> ws+last year
                    semester = "ws" + DateTime.Now.AddYears(-1).Year.ToString().Substring(2);
                }
                else if (DateTime.Now.Month > 9)
                {
                    // winter semester, still in this year
                    semester = "ws" + DateTime.Now.Year.ToString().Substring(2);
                }
                else
                {
                    // summer semester
                    semester = "ss" + DateTime.Now.Year.ToString().Substring(2);
                }
                courses = await api.RESTCalls.L2PViewAllCourseIfoBySemesterAsync(semester);
            }

            // TODO Workaround (should be moved to Manager)
            if (courses == null)
            {
                await api.AuthenticationManager.GenerateAccessTokenFromRefreshTokenAsync();

                courses = await api.RESTCalls.L2PViewAllCourseInfoAsync();

                return;
            }

            if (courses.dataset == null)
            {
                ErrorMessage = courses.errorDescription;
                return;
            }

            MenuPage.ClearCoursesMenu();
            foreach (L2PCourseInfoData l2pcourse in courses.dataset)
            {
                MenuPage.AddCourseToMenu(l2pcourse.uniqueid, l2pcourse.courseTitle);
            }
            LoadingCourses = false;
            Ready          = true;
            //IsBusy = false;
        }
Пример #2
0
        private async Task RefreshNavbar(bool useAll)
        {
            IsBusy = true;


            if (api.AuthenticationManager.getState() != api.AuthenticationManager.AuthenticationState.ACTIVE)
            {
                Device.BeginInvokeOnMainThread(() => DisplayAlert("Authorization needed", "Please authorize the App first", "OK"));
                IsBusy = false;
                return;
            }

            //var c = new System.Net.Http.HttpClient();

            // Get the courses!
            L2PCourseInfoSetData courses;

            if (useAll)
            {
                courses = await api.RESTCalls.L2PViewAllCourseInfoAsync();
            }
            else
            {
                string semester;
                if (DateTime.Now.Month < 4)
                {
                    // winter semester but already in new year -> ws+last year
                    semester = "ws" + DateTime.Now.AddYears(-1).Year.ToString().Substring(2);
                }
                else if (DateTime.Now.Month > 9)
                {
                    // winter semester, still in this year
                    semester = "ws" + DateTime.Now.Year.ToString().Substring(2);
                }
                else
                {
                    // summer semester
                    semester = "ss" + DateTime.Now.Year.ToString().Substring(2);
                }
                courses = await api.RESTCalls.L2PViewAllCourseIfoBySemesterAsync(semester);
            }

            // Workaround (should be moved to Manager)
            if (courses == null)
            {
                await api.AuthenticationManager.GenerateAccessTokenFromRefreshTokenAsync();

                courses = await api.RESTCalls.L2PViewAllCourseInfoAsync();
            }

            if (courses.dataset == null)
            {
                Device.BeginInvokeOnMainThread(() => DisplayAlert("Error", "An error occured: " + courses.errorDescription, "OK"));
                IsBusy = false;
                return;
            }

            MenuPage.ClearCoursesMenu();
            foreach (L2PCourseInfoData l2pcourse in courses.dataset)
            {
                MenuPage.AddCourseToMenu(l2pcourse.uniqueid, l2pcourse.courseTitle);
            }

            IsBusy = false;
        }