コード例 #1
0
        private async void SavePedido()
        {
            this.IsRunning     = true;
            this.IsEnabled     = false;
            this.IsEnabledSave = false;
            //Obteniendo ubicación actual
            await this.geolocation.GetLocationAsync();

            var ubicacion = "";

            if (geolocation.Latitude != 0 && geolocation.Longitude != 0)
            {
                Position position = new Position(
                    geolocation.Latitude,
                    geolocation.Longitude);
                ubicacion = geolocation.Latitude.ToString() + "," + geolocation.Longitude.ToString();
            }

            //var byteArray = this.ImageSourceToByteArray(ImageSource);
            //var stringBase64 = Convert.ToBase64String(byteArray);

            //Armando body de petición
            JArray  arrPrincipal = new JArray();
            JObject pedido       = new JObject();

            pedido["Pedido"] = this.Pedido.Identifier;
            JArray evidencias = new JArray();

            //Armar objetos de evidencias
            if (this.imgEv1Base64 != "")
            {
                JObject objEvidencia = new JObject();
                objEvidencia["Imagen"] = this.imgEv1Base64;
                objEvidencia["Tipo"]   = 2;
                evidencias.Add(objEvidencia);
            }

            if (this.imgEv2Base64 != "")
            {
                JObject objEvidencia2 = new JObject();
                objEvidencia2["Imagen"] = this.imgEv2Base64;
                objEvidencia2["Tipo"]   = 2;
                evidencias.Add(objEvidencia2);
            }

            if (this.imgEv3Base64 != "")
            {
                JObject objEvidencia3 = new JObject();
                objEvidencia3["Imagen"] = this.imgEv3Base64;
                objEvidencia3["Tipo"]   = 2;
                evidencias.Add(objEvidencia3);
            }

            if (this.imgEv4Base64 != "")
            {
                JObject objEvidencia4 = new JObject();
                objEvidencia4["Imagen"] = this.imgEv4Base64;
                objEvidencia4["Tipo"]   = 2;
                evidencias.Add(objEvidencia4);
            }

            //Objeto firma
            if (this.imgFirmaBase64 != "")
            {
                JObject objFirma = new JObject();
                objFirma["Imagen"] = this.imgFirmaBase64;
                objFirma["Tipo"]   = 1;
                evidencias.Add(objFirma);
            }


            pedido["Evidencias"] = evidencias;
            pedido["Status"]     = 2;//Entregado
            pedido["Ubicacion"]  = ubicacion;

            arrPrincipal.Add(pedido);

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

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

                return;
            }

            var response = await apiService.ActualizarPedido("https://apps.fussionweb.com/", "sie/Mobile", "/ActualizarPedido", arrPrincipal);

            //var response = await apiService.ActualizarPedido("https://apps.fussionweb.com/", "sietest/Mobile", "/ActualizarPedido", arrPrincipal);

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

                return;
            }
            this.IsRunning     = false;
            this.IsEnabled     = true;
            this.IsEnabledSave = true;

            await Application.Current.MainPage.DisplayAlert("Éxito", response.Message, "Aceptar");

            MainViewModel.GetInstace().Pedidos = new PedidosViewModel();
            //await App.Navigator.PopAsync();
            //MainPage = new MasterPageChofer();
            Application.Current.MainPage = new MasterPageChofer();
        }