private async Task exportarPedidos() { try { //Cargar todos los pedidos editables de este vendedor List <Pedido> pedidosExportar; using (var cPedidos = new ControladorPedido()) { pedidosExportar = cPedidos.FindForExport(this.IdVendedor); } //Por cada pedido encontrado foreach (Pedido pedExportar in pedidosExportar) { //Se guardan sus detalles List <Detalle> detExportar; using (var cDetalle = new ControladorDetalle()) { detExportar = cDetalle.FindByPedido(pedExportar.IdPedido); } //Se pasan a formato JSON var pedidoJson = JsonConvert.SerializeObject(pedExportar, Newtonsoft.Json.Formatting.Indented); var detallesJson = JsonConvert.SerializeObject(detExportar, Newtonsoft.Json.Formatting.Indented); //Se crea una lista de parejas var parejas = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("pedido", pedidoJson), new KeyValuePair <string, string>("detalles", detallesJson) }; //Se le da formato de formulario var contenido = new FormUrlEncodedContent(parejas); //Se envia el pedido y sus detalles correspondientes al servidor HttpClient clienteHttp = new HttpClient(); clienteHttp.BaseAddress = new Uri(this.Direccion); clienteHttp.Timeout = TimeSpan.FromSeconds(30); string url = string.Format("/Importar.aspx"); HttpResponseMessage respuesta = clienteHttp.PostAsync(url, contenido).Result; if (respuesta.IsSuccessStatusCode) { //Se cambia el atributo "editable" en todos los pedidos que fueron exportados pedExportar.Editable = false; using (var pControlador = new ControladorPedido()) { pControlador.Update(pedExportar); } } } exportarIndicator.IsVisible = false; imgExportar.IsVisible = true; if (pedidosExportar.Count > 0) { await DisplayAlert("Exportacion exitosa", "Los pedidos se exportaron exitosamente", "Aceptar"); App.Current.MainPage = new Pedidos(this.IdVendedor, this.Direccion); } else { await DisplayAlert("Exportacion fallida", "No hay ningun pedido para exportar", "Aceptar"); } } catch (Exception) { exportarIndicator.IsVisible = false; imgExportar.IsVisible = true; await DisplayAlert("Error de conexión", "No se pudo enviar la informacion al sitio web. Compruebe que su conexión a internet este funcionando correctamente.", "Aceptar"); } }