Exemplo n.º 1
0
        public ObservacionViewModel()
        {
            instance = this;

            apiService    = new ApiService();
            dialogService = new DialogService();

            LoadObservations();
        }
Exemplo n.º 2
0
        async void Go()
        {
            if (TitleBtn == "Agregar")
            {
                if (string.IsNullOrEmpty(Observation))
                {
                    await dialogService.ShowMessage(
                        "Error",
                        "Debe ingresar una observación.");

                    return;
                }

                IsRunning = true;
                IsEnabled = false;

                var connection = await apiService.CheckConnection();

                if (!connection.IsSuccess)
                {
                    IsRunning = false;
                    IsEnabled = true;
                    await dialogService.ShowMessage("Error", connection.Message);

                    return;
                }

                var observacion = new Observacion
                {
                    Descripcion = Observation,
                };

                var urlAPI = Application.Current.Resources["URLAPI"].ToString();

                var response = await apiService.Post(
                    urlAPI,
                    "/api",
                    "/Observacions",
                    observacion);

                if (!response.IsSuccess)
                {
                    IsRunning = false;
                    IsEnabled = true;
                    await dialogService.ShowMessage(
                        "Error",
                        response.Message);

                    return;
                }

                observacion = (Observacion)response.Result;
                var observacionViewModel = ObservacionViewModel.GetInstance();
                observacionViewModel.Add(observacion);

                await navigationService.BackOnMaster();

                IsRunning = false;
                IsEnabled = true;
            }
            else
            {
                if (string.IsNullOrEmpty(Observation))
                {
                    await dialogService.ShowMessage(
                        "Error",
                        "Debe ingresar una observación.");

                    return;
                }

                IsRunning = true;
                IsEnabled = false;

                var connection = await apiService.CheckConnection();

                if (!connection.IsSuccess)
                {
                    IsRunning = false;
                    IsEnabled = true;
                    await dialogService.ShowMessage("Error", connection.Message);

                    return;
                }

                observacion.Descripcion = Observation;

                var urlAPI = Application.Current.Resources["URLAPI"].ToString();

                var response = await apiService.Put(
                    urlAPI,
                    "/api",
                    "/Observacions",
                    observacion);

                if (!response.IsSuccess)
                {
                    IsRunning = false;
                    IsEnabled = true;
                    await dialogService.ShowMessage(
                        "Error",
                        response.Message);

                    return;
                }

                var observacionViewModel = ObservacionViewModel.GetInstance();
                observacionViewModel.Update(observacion);

                await navigationService.BackOnMaster();

                IsRunning = false;
                IsEnabled = true;
            }
        }