Пример #1
0
        public ParqueoViewModel()
        {
            instance      = this;
            dialogService = new DialogService();
            apiService    = new ApiService();

            LoadParking();
        }
Пример #2
0
        async void Go()
        {
            if (string.IsNullOrEmpty(Descripcion))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "Debe ingresar una descripción.");

                return;
            }

            if (string.IsNullOrEmpty(Direccion))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "Debe ingresar una dirección.");

                return;
            }


            if (string.IsNullOrEmpty(NumeroZonas.ToString()))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "Debe ingresar el número de zonas.");

                return;
            }


            IsRunning = true;
            IsEnabled = false;

            var connection = await apiService.CheckConnection();

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

                return;
            }

            if (TitleBtn == "Agregar")
            {
                var parking = new Parking
                {
                    Descripcion = Descripcion,
                    Direccion   = Direccion,
                    NumeroZonas = NumeroZonas
                };

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

                var response = await apiService.Post(
                    urlAPI,
                    "/api",
                    "/Parqueos",
                    parking);

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

                    return;
                }

                parking = (Parking)response.Result;
                var parqueoviewModel = ParqueoViewModel.GetInstance();
                parqueoviewModel.Add(parking);

                await navigationService.BackOnMaster();

                IsRunning = false;
                IsEnabled = true;
            }
            else
            {
                parking.Descripcion = Descripcion;
                parking.Direccion   = Direccion;
                parking.NumeroZonas = NumeroZonas;

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

                var response = await apiService.Put(
                    urlAPI,
                    "/api",
                    "/Parqueos",
                    parking);

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

                    return;
                }

                var parqueosViewModel = ParqueoViewModel.GetInstance();
                parqueosViewModel.Update(parking);

                await navigationService.BackOnMaster();

                IsRunning = false;
                IsEnabled = true;
            }
        }