Esempio n. 1
0
        private async void Editar_Clicked(object sender, EventArgs e)
        {
            var oauthToken = await SecureStorage.GetAsync("auth");

            Personas personas = JsonConvert.DeserializeObject <Personas>(oauthToken);

            cliente.DefaultRequestHeaders.Add("Accept", "application/json");

            Negos   negocios = new Negos();
            Negocio nego     = new Negocio();

            List <Negocio> negocio = new List <Negocio>();

            nego.idnegocio = viewModel.Negocio.idnegocio;
            nego.idadmin   = personas.persona[0].id;
            nego.nombre    = nom.Text;
            nego.nit       = nit.Text;
            nego.email     = email.Text;
            nego.direccion = direccion.Text;
            nego.telefono  = telefono.Text;
            nego.tipo      = (string)tipo.SelectedItem;
            nego.ciudad    = ciudad.Text;
            nego.detalle   = detalle.Text;
            nego.foto      = urlImagen;

            Geolocalizacion geo     = new Geolocalizacion();
            List <double>   latLong = await geo.calcularCoordenadas(nego.direccion);

            if (latLong == null)
            {
                nego.latitud  = "";
                nego.longitud = "";
                await DisplayAlert("Problema con la direccion", "No fue posible verficar la dirección", "OK");

                return;
            }
            else
            {
                nego.latitud  = latLong.ElementAt(0).ToString().Replace(",", ".");
                nego.longitud = latLong.ElementAt(1).ToString().Replace(",", ".");
                //await DisplayAlert("Direccion correcta", "Latitud: " + nego.latitud + " Longitud: " + nego.longitud, "ok");
            }

            if (string.IsNullOrEmpty(nego.nombre))
            {
                await Application.Current.MainPage.DisplayAlert("error", "Campo nombre no puede estar vacio", "Accept");

                return;
            }

            else if (string.IsNullOrEmpty(nego.nit))
            {
                await Application.Current.MainPage.DisplayAlert("error", "Se debe ingresar un nit", "Accept");

                return;
            }

            else if (string.IsNullOrEmpty(nego.email))
            {
                await Application.Current.MainPage.DisplayAlert("error", "Debes ingresar un correo", "Accept");

                return;
            }

            else if (!utilidades.email_bien_escrito(nego.email))
            {
                await Application.Current.MainPage.DisplayAlert("error", "Correo no admitido", "Accept");

                return;
            }

            else if (string.IsNullOrEmpty(nego.telefono))
            {
                await Application.Current.MainPage.DisplayAlert("error", "Ingresa un telefono", "Accept");

                return;
            }

            else if (string.IsNullOrEmpty(nego.direccion))
            {
                await Application.Current.MainPage.DisplayAlert("error", "ingresa", "Accept");

                return;
            }

            else if (string.IsNullOrEmpty(nego.ciudad))
            {
                await Application.Current.MainPage.DisplayAlert("error", "you must enter a city", "Accept");

                return;
            }


            else if (string.IsNullOrEmpty(nego.detalle))
            {
                await Application.Current.MainPage.DisplayAlert("error", "you must enter a detail", "Accept");

                return;
            }


            else if (string.IsNullOrEmpty(nego.foto))
            {
                nego.foto = fotoVieja;
            }

            negocio.Add(nego);

            negocios.negocio = negocio;

            var json    = JsonConvert.SerializeObject(negocios);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            var response = await cliente.PutAsync(URL, content);

            var res = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine(res);
                await App.Current.MainPage.DisplayAlert("Actualizar", "Editar Completado", "OK");

                n.actualizarVistaAsync();
                await Navigation.PopModalAsync();
            }
            else
            {
                Console.WriteLine(res);
                await App.Current.MainPage.DisplayAlert("Error", "Algo salió mal", "OK");

                Console.WriteLine("Error");
            }
        }
Esempio n. 2
0
        private async void Eliminar_Clicked(object sender, EventArgs e)
        {
            var confirm = await DisplayAlert("Confirmación", "¿Está seguro de eliminar este negocio?", "Si", "No");

            Console.WriteLine("Respuesta: " + confirm);

            if (confirm)
            {
                var negocioItem = viewModel.Negocio;

                cliente.DefaultRequestHeaders.Add("Accept", "application/json");

                Negos   negocios = new Negos();
                Negocio nego     = new Negocio();

                List <Negocio> negocio = new List <Negocio>();

                nego.idnegocio = negocioItem.idnegocio;
                nego.parametro = "1152";
                nego.idadmin   = "";
                nego.nombre    = "";
                nego.nit       = "";
                nego.email     = "";
                nego.direccion = "";
                nego.telefono  = "";
                nego.tipo      = "";
                nego.ciudad    = "";
                nego.detalle   = "";
                nego.foto      = "";
                nego.latitud   = "";
                nego.longitud  = "";

                negocio.Add(nego);

                negocios.negocio = negocio;

                var json = JsonConvert.SerializeObject(negocios);

                var content = new StringContent(json, Encoding.UTF8, "application/json");

                var response = await cliente.PutAsync(URL, content);

                var res = response.Content.ReadAsStringAsync();

                Console.WriteLine("Body: " + json);

                if (response.IsSuccessStatusCode)
                {
                    Console.WriteLine("respuesta: " + res);
                    await App.Current.MainPage.DisplayAlert("Correcto", "Negocio Eliminado", "OK");

                    n.actualizarVistaAsync();
                    await Navigation.PopModalAsync();
                }
                else
                {
                    Console.WriteLine("respuesta: " + res);
                    await App.Current.MainPage.DisplayAlert("Error", "Algo salió mal", "OK");
                }
            }
        }