Ejemplo n.º 1
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");
            }
        }