Exemplo n.º 1
0
        async Task CreateInstructor()
        {
            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 instructorService.CheckConnection();

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

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

                    return;
                }

                var instructorDTO = new InstructorDTO {
                    LastName = this.LastName, FirstMidName = this.FirstMidName, HireDate = this.HireDate
                };
                await instructorService.Create(Endpoints.POST_Instructor, instructorDTO);

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

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

                this.InstructorID = 0;
                this.LastName     = this.FirstMidName = string.Empty;
                //this.HireDate = DateTime.Now;


                //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");
            }
        }
        async Task CreateInstructor()
        {
            try
            {
                if (string.IsNullOrEmpty(LastName) || string.IsNullOrEmpty(FirstMidName))
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "You must enter the field all", "Cancel");

                    return;
                }

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

                var connection = await instructorService.CheckConnection();

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

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

                    return;
                }

                var instructorDTO = new InstructorDTO {
                    LastName = this.LastName, FirstMidName = this.FirstMidName, HireDate = this.HireDate
                };
                await instructorService.Create(Endpoints.POST_INSTRUCTORS, instructorDTO);

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

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

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

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