Exemple #1
0
        public async void Eliminar_Clicked(object sender, EventArgs e)
        {
            var confirm = await DisplayAlert("Confirmación", "¿Está seguro de eliminar este negocio?", "Si", "No");

            if (confirm)
            {
                var mi         = ((MenuItem)sender);
                var ofertaItem = mi.CommandParameter as Oferta;

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

                Oferts ofertas = new Oferts();
                Oferta ofer    = new Oferta();

                List <Oferta> oferta = new List <Oferta>();

                ofer.id           = ofertaItem.id;
                ofer.parametro    = "1";
                ofer.producto     = "";
                ofer.detalle      = "";
                ofer.valor        = "";
                ofer.descuento    = "";
                ofer.foto         = "";
                ofer.idnegocio    = "";
                ofer.fecha_inicio = "";
                ofer.fecha_fin    = "";
                ofer.latitud      = "";
                ofer.longitud     = "";
                ofer.tipo         = "";

                oferta.Add(ofer);


                ofertas.oferta = oferta;

                var json = JsonConvert.SerializeObject(ofertas);

                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);
                    actualizarVistaAsync();
                    await App.Current.MainPage.DisplayAlert("Correcto", "Oferta Eliminada", "OK");
                }
                else
                {
                    Console.WriteLine("respuesta: " + res);
                    await App.Current.MainPage.DisplayAlert("Error", "Algo salió mal", "OK");
                }
            }
        }
Exemple #2
0
        private async void Agregar_Clicked(object sender, EventArgs e)
        {
            var oauthToken = await SecureStorage.GetAsync("auth");

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

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

            Oferts ofertas = new Oferts();
            Oferta ofert   = new Oferta();

            List <Oferta> oferta = new List <Oferta>();

            ofert.producto     = producto.Text;
            ofert.tipo         = (string)tipo.SelectedItem;
            ofert.detalle      = detalle.Text;
            ofert.valor        = valor.Text;
            ofert.descuento    = descuento.Text;
            ofert.idnegocio    = this.idnegocio;
            ofert.fecha_inicio = fecha_inicial;
            ofert.fecha_fin    = fecha_final;
            ofert.foto         = urlImagen;
            ofert.latitud      = "";
            ofert.longitud     = "";


            if (string.IsNullOrEmpty(ofert.fecha_inicio))
            {
                ofert.fecha_inicio = actual.ToString("dd/MM/yyyy");
            }
            else if (string.IsNullOrEmpty(ofert.producto))
            {
                await Application.Current.MainPage.DisplayAlert("error", "Producto no puede estar vacio", "Accept");

                return;
            }
            else if (string.IsNullOrEmpty(ofert.detalle))
            {
                await Application.Current.MainPage.DisplayAlert("error", "Debes ingresar un detalle", "Accept");

                return;
            }
            else if (string.IsNullOrEmpty(ofert.valor))
            {
                await Application.Current.MainPage.DisplayAlert("error", "Valor no puede estar vacio", "Accept");

                return;
            }
            else if (string.IsNullOrEmpty(ofert.descuento))
            {
                await Application.Current.MainPage.DisplayAlert("error", "ingresa como es el descuento o promoción", "Accept");

                return;
            }

            else if (string.IsNullOrEmpty(ofert.fecha_fin))
            {
                await Application.Current.MainPage.DisplayAlert("error", "Debes ingresar una fecha final", "Accept");

                return;
            }
            else if (string.IsNullOrEmpty(ofert.foto))
            {
                await Application.Current.MainPage.DisplayAlert("error", "Debes escoger una foto", "Accept");

                return;
            }
            else if (fechaI > fechaF)
            {
                await Application.Current.MainPage.DisplayAlert("error", "No es posible que la fecha inicial sea mayor a la final", "cancel");

                return;
            }



            oferta.Add(ofert);

            ofertas.oferta = oferta;

            var json = JsonConvert.SerializeObject(ofertas);

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

            Console.WriteLine("Body a enviar: " + content);
            var response = await cliente.PostAsync(URL, content);

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

            if (response.IsSuccessStatusCode || response.StatusCode.Equals("202"))
            {
                await App.Current.MainPage.DisplayAlert("Registro", "Registro Completado", "OK");

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

                Console.WriteLine("Error");
            }
        }
Exemple #3
0
        private async void btnEditar_Clicked(object sender, EventArgs e)
        {
            cliente.DefaultRequestHeaders.Add("Accept", "application/json");

            Oferts ofertas = new Oferts();
            Oferta ofert   = new Oferta();

            List <Oferta> oferta = new List <Oferta>();

            ofert.id           = viewModel.Oferta.id;
            ofert.parametro    = viewModel.Oferta.idnegocio;
            ofert.producto     = producto.Text;
            ofert.tipo         = (string)tipo.SelectedItem;
            ofert.detalle      = detalle.Text;
            ofert.valor        = valor.Text;
            ofert.descuento    = descuento.Text;
            ofert.idnegocio    = viewModel.Oferta.idnegocio;
            ofert.fecha_inicio = fecha_inicial;
            ofert.fecha_fin    = fecha_final;
            ofert.foto         = urlImagen;
            ofert.latitud      = "";
            ofert.longitud     = "";


            if (string.IsNullOrEmpty(ofert.producto))
            {
                await Application.Current.MainPage.DisplayAlert("error", "Producto no puede estar vacio", "Accept");

                return;
            }
            if (string.IsNullOrEmpty(ofert.detalle))
            {
                await Application.Current.MainPage.DisplayAlert("error", "Debes ingresar un detalle", "Accept");

                return;
            }
            if (string.IsNullOrEmpty(ofert.valor))
            {
                await Application.Current.MainPage.DisplayAlert("error", "Valor no puede estar vacio", "Accept");

                return;
            }
            if (string.IsNullOrEmpty(ofert.descuento))
            {
                await Application.Current.MainPage.DisplayAlert("error", "ingresa como es el descuento o promoción", "Accept");

                return;
            }

            if (string.IsNullOrEmpty(ofert.fecha_inicio))
            {
                ofert.fecha_inicio = parsedDateInicio.ToString("dd/MM/yyyy");
                if (parsedDateInicio < actual)
                {
                    await Application.Current.MainPage.DisplayAlert("error", "debes ingresar una fecha inicial mayor o igual a la actual", "Accept");

                    return;
                }


                //return;
            }
            if (string.IsNullOrEmpty(ofert.fecha_fin))
            {
                ofert.fecha_fin = parsedDateFin.ToString("dd/MM/yyyy");
                if (parsedDateFin < actual)
                {
                    await Application.Current.MainPage.DisplayAlert("error", "debes ingresar una fecha final mayor o igual a la actual", "Accept");

                    return;
                }
            }
            if (fechaI > fechaF)
            {
                await Application.Current.MainPage.DisplayAlert("error", "No es posible que la fecha inicial sea mayor a la final", "cancel");

                return;
            }

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

            oferta.Add(ofert);

            ofertas.oferta = oferta;

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

            Console.WriteLine("json: " + 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");

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

                Console.WriteLine("Error");
            }
        }