Ejemplo n.º 1
0
        async Task GetStudents()
        {
            try
            {
                this.IsRefreshing = true;

                var connection = await studentService.CheckConnection();

                if (!connection)
                {
                    this.IsRefreshing = false;
                    await Application.Current.MainPage.DisplayAlert("Error", "No internet connection", "Cancel");

                    return;
                }
                var listStudents = (await studentService.GetAll(Endpoints.GET_STUDENTS)).Select(x => ToStudentItemViewModel(x));
                this.AllStudents  = listStudents.ToList();
                this.Students     = new ObservableCollection <StudentItemViewModel>(listStudents);
                this.IsRefreshing = false;
            }
            catch (Exception ex)
            {
                this.IsRefreshing = false;
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Cancel");
            }
        }
        async Task DeleteStudent()
        {
            var answer = await Application.Current.MainPage.DisplayAlert("Confirm", "Delete confirm", "Yes", "No");

            if (!answer)
            {
                return;
            }

            var connection = await studentService.CheckConnection();

            if (!connection)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "No internet connection", "Cancel");

                return;
            }

            await studentService.Delete(Endpoints.DELETE_STUDENTS, this.ID);

            await Application.Current.MainPage.DisplayAlert("Message", "The process is successful", "Confirm");

            var studentViewModel = StudentsViewModel.GetInstance();
            var studentDelete    = studentViewModel.AllStudents.FirstOrDefault(x => x.ID == this.ID);

            studentViewModel.AllStudents.Remove(studentDelete);
            studentViewModel.GetStudentsByName();
        }
Ejemplo n.º 3
0
        async Task GetStudentsByCourse()
        {
            try
            {
                this.IsRefreshing = true;

                var connection = await studentService.CheckConnection();

                if (!connection)
                {
                    this.IsRefreshing = false;
                    await Application.Current.MainPage.DisplayAlert("Error", "No internet connection", "Cancel");

                    return;
                }

                var listStudents = (await studentService.GetAll(Endpoints.GET_STUDENTS_BY_COURSE + this.course.CourseID)).OrderByDescending(x => x.ID);
                this.Students     = new ObservableCollection <StudentDTO>(listStudents);
                this.IsRefreshing = false;
            }
            catch (Exception ex)
            {
                this.IsRefreshing = false;
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Cancel");
            }
        }
        async Task EditStudent()
        {
            try
            {
                if (string.IsNullOrEmpty(this.Student.LastName))
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "You must enter the field LastName", "Cancel");

                    return;
                }

                this.IsRunning = true;
                this.IsEnabled = false;

                var connection = await studentService.CheckConnection();

                if (!connection)
                {
                    this.IsRunning = false;
                    this.IsEnabled = true;

                    await Application.Current.MainPage.DisplayAlert("Error", "No internet connection", "Cancel");

                    return;
                }

                var studentDTO = new StudentDTO {
                    ID = this.Student.ID, LastName = this.Student.LastName, FirstMidName = this.Student.FirstMidName, EnrollmentDate = this.Student.EnrollmentDate
                };
                await studentService.Update(Endpoints.PUT_STUDENTS, this.Student.ID, studentDTO);

                this.IsRunning = false;
                this.IsEnabled = true;

                await Application.Current.MainPage.DisplayAlert("Message", "The process is successful", "Cancel");

                this.Student.ID             = this.Student.ID = 0;
                this.Student.LastName       = string.Empty;
                this.Student.FirstMidName   = string.Empty;
                this.Student.EnrollmentDate = DateTime.Now;

                await Application.Current.MainPage.Navigation.PopAsync();
            }
            catch (Exception ex)
            {
                this.IsRunning = false;
                this.IsEnabled = true;

                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Cancel");
            }
        }
Ejemplo n.º 5
0
        async Task CreateStudent()
        {
            try
            {
                if (string.IsNullOrEmpty(this.LastName))
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "You must enter the field lastName", "Cancel");

                    return;
                }

                this.IsRunning = true;
                this.IsEnabled = false;

                var connection = await studentService.CheckConnection();

                if (!connection)
                {
                    this.IsRunning = false;
                    this.IsEnabled = true;

                    await Application.Current.MainPage.DisplayAlert("Error", "No internet connection", "Cancel");

                    return;
                }

                var studentDTO = new StudentDTO {
                    LastName = this.LastName, FirstMidName = this.FirstMidName, EnrollmentDate = this.EnrollmentDate
                };
                await studentService.Create(Endpoints.POST_Students, studentDTO);

                this.IsRunning = false;
                this.IsEnabled = true;

                await Application.Current.MainPage.DisplayAlert("Message", "The process is successful", "Cancel");

                this.ID             = 0;
                this.LastName       = this.FirstMidName = string.Empty;
                this.EnrollmentDate = DateTime.UtcNow;

                //Application.Current.MainPage = new NavigationPage(new CoursesPage());
            }
            catch (Exception ex)
            {
                this.IsRunning = false;
                this.IsEnabled = true;

                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Cancel");
            }
        }