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

                var connection = await InstructorService.CheckConnection();

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

                    return;
                }

                var listInstructors = ((await InstructorService.GetAll(Endpoints.GET_Instructors)).Select(x => ToInstructorItemViewModel(x))).OrderByDescending(x => x.FirstMidName);
                this.AllInstructors = listInstructors.ToList();
                this.Instructors    = new ObservableCollection <InstructorItemViewModel>(listInstructors);
                this.IsRefreshing   = false;
            }
            catch (Exception ex)
            {
                this.IsRefreshing = false;
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Cancel");
            }
        }
Exemplo n.º 2
0
        async Task DeleteInstructor()
        {
            var answer = await Application.Current.MainPage.DisplayAlert("Confirm", "Delete Confirm", "Yes", "No");

            if (!answer)
            {
                return;
            }

            var connection = await instructorService.CheckConnection();

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

                return;
            }

            await instructorService.Delete(EndPoints.DELETE_INSTRUCTORS, this.ID);

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

            var instructorViewModel = InstructorsViewModel.GetInstance();
            var instructorDeleted   = instructorViewModel.AllInstructors.FirstOrDefault(x => x.ID == this.ID);

            instructorViewModel.AllInstructors.Remove(instructorDeleted);
            instructorViewModel.GetInstructorsByFullName();
        }
        async Task EditInstructor()
        {
            try
            {
                if (string.IsNullOrEmpty(this.Instructor.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 {
                    ID = this.Instructor.ID, LastName = this.Instructor.LastName, FirstMidName = this.Instructor.FirstMidName, HireDate = this.Instructor.HireDate
                };
                await instructorService.Update(Endpoints.PUT_INSTRUCTORS, this.Instructor.ID, instructorDTO);

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

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

                this.Instructor.ID           = this.Instructor.ID = 0;
                this.Instructor.LastName     = string.Empty;
                this.Instructor.FirstMidName = string.Empty;
                this.Instructor.HireDate     = 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");
            }
        }
Exemplo n.º 4
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");
            }
        }