Exemplo n.º 1
0
        private async void Delete()
        {
            var answer = await Application.Current.MainPage.DisplayAlert(Languages.Delete, Languages.DeleteConfirmation, Languages.Yes, Languages.No);

            if (!answer)
            {
                return;
            }

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

            var Conecction = await this.apiService.CheckConnection();

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

                await Application.Current.MainPage.DisplayAlert(Languages.Error, Conecction.Message, Languages.Accept);

                return;
            }

            var url        = Application.Current.Resources["UrlAPI"].ToString();
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlFincasController"].ToString();
            var response   = await this.apiService.Delete(url, prefix, controller, this.Finca.FincaId, Settings.TokenType, Settings.AccessToken); //, Settings.TokenType, Settings.AccessToken);

            if (!response.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(Languages.Error, response.Message, Languages.Accept);

                return;
            }

            var fincaViewModel = FincasViewModel.GetInstance();
            var deleteProducto = fincaViewModel.myFincas.Where(o => o.FincaId == this.Finca.FincaId).FirstOrDefault();

            if (deleteProducto != null)
            {
                fincaViewModel.myFincas.Remove(deleteProducto);
            }

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

            fincaViewModel.RefreshList();
            await App.Navigator.PopAsync();
        }
Exemplo n.º 2
0
        private async void Save()
        {
            if (String.IsNullOrEmpty(this.NombreFinca))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.NameError
                                                                , Languages.Accept);

                return;
            }

            if (String.IsNullOrEmpty(this.PaisFinca))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.CoutryError
                                                                , Languages.Accept);

                return;
            }

            if (String.IsNullOrEmpty(this.EstadoFinca))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.StateError
                                                                , Languages.Accept);

                return;
            }

            if (String.IsNullOrEmpty(this.CiudadFinca))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.CityError
                                                                , Languages.Accept);

                return;
            }

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

            var connection = await this.apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(Languages.Error, connection.Message, Languages.Accept);

                return;
            }

            byte[] imageArray = null;
            if (this.file != null)
            {
                imageArray = FilesHelper.ReadFully(this.file.GetStream());
            }

            var finca = new Fincas
            {
                CiudadFinca     = this.CiudadFinca,
                EstadoFinca     = this.EstadoFinca,
                HabilitadaFinca = this.HabilitadaFinca,
                NombreFinca     = this.NombreFinca,
                PaisFinca       = this.PaisFinca,
                IngresoFinca    = this.IngresoFinca,
                ImageArray      = imageArray,
            };

            var url        = Application.Current.Resources["UrlAPI"].ToString();
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlFincasController"].ToString();
            var response   = await this.apiService.Post(url, prefix, controller, finca, Settings.TokenType, Settings.AccessToken);

            if (!response.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    response.Message,
                    Languages.Accept);

                return;
            }

            var newFinca        = (Fincas)response.Result;
            var fincasViewModel = FincasViewModel.GetInstance();

            fincasViewModel.myFincas.Add(newFinca);
            fincasViewModel.RefreshList();

            this.IsRunning = false;
            this.IsEnabled = true;
            await App.Navigator.PopAsync();
        }