Ejemplo n.º 1
0
        private void loadData()
        {
            isLoading = false;

            Models.AllStudentsResponse        resp;
            Task <Models.AllStudentsResponse> task = Task.Run(() => restService.GetAllStudentsAsync());

            task.ContinueWith(t => Device.BeginInvokeOnMainThread(
                                  async() =>
            {
                if (t.IsFaulted)
                {
                    await App.Current.MainPage.DisplayAlert("Connection error", "There was an error connecting to the server", "Try Again");
                }
                resp = t.Result;
                if (!resp.Success)
                {
                    await App.Current.MainPage.DisplayAlert(resp.Error.Message, resp.Error.Detail, "Try again");
                    isLoading = true;
                    return;
                }
                Students = resp.Students.values;

                students.Clear();

                students.Add(new StudentTemp()
                {
                    Forename = "New Student", CurrentGradeNumber = 1, newStudent = true
                });

                foreach (var s in Students)
                {
                    StudentTemp st = new StudentTemp(s);
                    st.newStudent  = false;
                    students.Add(st);
                }

                isLoading = true;
            }
                                  ));
        }
Ejemplo n.º 2
0
        private void loadData()
        {
            isRefreshing = true;
            Models.AllStudentsResponse        resp;
            Task <Models.AllStudentsResponse> task = Task.Run(() => restService.GetAllStudentsAsync());

            task.ContinueWith(t => Device.BeginInvokeOnMainThread(
                                  async() =>
            {
                if (t.IsFaulted)
                {
                    await App.Current.MainPage.DisplayAlert("Connection error", "There was an error connecting to the server", "Try Again");
                }
                resp = t.Result;
                if (!resp.Success)
                {
                    isRefreshing = false;
                    await App.Current.MainPage.DisplayAlert(resp.Error.Message, resp.Error.Detail, "Try again");
                    return;
                }
                Students = resp.Students.values;

                students.Clear();



                foreach (var s in Students)
                {
                    StudentCell cell = new StudentCell(s);
                    cell.textColour  = Application.Current.Resources["OnSurface"] as Color? ?? Color.Black;
                    students.Add(cell);
                }
                isRefreshing = false;
                search();
            }
                                  ));
        }