public async Task <Response> PostMaster( string urlBase, string controller, SyncShiptoRequest shiptorequest ) { try { var body = JsonConvert.SerializeObject(shiptorequest); var content = new StringContent(body, Encoding.UTF8, "application/json"); var client = new HttpClient(); client.BaseAddress = new Uri(urlBase); var response = await client.PostAsync(controller, content); var result = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { var error = JsonConvert.DeserializeObject <Response>(result); return(new Response { IsSuccess = false, Message = error.Message, }); } var shipto = JsonConvert.DeserializeObject <SyncShiptoRequest>(result); return(new Response { IsSuccess = true, Result = shipto, }); } catch (Exception ex) { return(new Response { IsSuccess = false, Message = ex.Message, }); } }
async void SaveShipTo() { try { var answer = await dialogService.ShowConfirm( "Confirmación", "¿Guardar sucursal?"); var connection = await netService.CheckConnectivity(); if (!connection.IsSuccess) { await dialogService.ShowMessage("Error", connection.Message); return; } if (string.IsNullOrEmpty(NewShipTo.ShipToNum)) { await dialogService.ShowMessage( "Error", "Debes ingresar un ShipToNum."); return; } if (string.IsNullOrEmpty(NewShipTo.ShipToName)) { await dialogService.ShowMessage( "Error", "Debes ingresar nombre de sucursal."); return; } if (string.IsNullOrEmpty(NewShipTo.Description)) { await dialogService.ShowMessage( "Error", "Debes seleccionar un pais."); return; } NewShipTo.IsRunning = true; //var UltimoRegistro = dataService //.Get<ShipTo>(false) //.OrderByDescending(t => t.ShipToId) //.FirstOrDefault(); //if (UltimoRegistro.ShipToId == 0) //{ // UltimoRegistro.ShipToId = 1; //}else{ // UltimoRegistro.ShipToId = UltimoRegistro.ShipToId + 1; //} var shipto = new ShipTo { ShipToId = 0, CustomerId = NewShipTo.CustomerId, CustNum = EditCustomer.Customer.CustNum, ShipToNum = NewShipTo.ShipToNum, Company = User.Company, ShipToName = NewShipTo.ShipToName, TerritoryEpicorID = NewShipTo.TerritoryEpicorID, Country = NewShipTo.Description, State = NewShipTo.State, City = NewShipTo.City, Address = NewShipTo.Address, PhoneNum = NewShipTo.PhoneNum, Email = NewShipTo.Email, SincronizadoEpicor = false, }; #region Sincronizo Shipto var url = Application.Current.Resources["URLAPI"].ToString(); var shiptorequest = new SyncShiptoRequest { ShipToId = shipto.ShipToId, CustomerId = shipto.CustomerId, ShipToNum = shipto.ShipToNum, CustNum = shipto.CustNum, Company = shipto.Company, ShipToName = shipto.ShipToName, TerritoryEpicorID = shipto.TerritoryEpicorID, Country = shipto.Country, State = shipto.State, City = shipto.City, Address = shipto.Address, PhoneNum = shipto.PhoneNum, Email = shipto.Email, VendorId = User.VendorId, SincronizadoEpicor = false, }; var response = await apiService .PostMaster(url, "/api/ShipToes", shiptorequest); if (!response.IsSuccess) { await dialogService.ShowMessage("Error", response.Message); return; } var syncShiptoRequest = (SyncShiptoRequest)response.Result; var ShipToToInsert = new ShipTo { Address = syncShiptoRequest.Address, City = syncShiptoRequest.City, Company = syncShiptoRequest.Company, Country = syncShiptoRequest.Country, CustNum = syncShiptoRequest.CustNum, CustomerId = syncShiptoRequest.CustomerId, Email = syncShiptoRequest.Email, PhoneNum = syncShiptoRequest.PhoneNum, ShipToId = syncShiptoRequest.ShipToId, ShipToName = syncShiptoRequest.ShipToName, ShipToNum = syncShiptoRequest.ShipToNum, SincronizadoEpicor = syncShiptoRequest.SincronizadoEpicor, State = syncShiptoRequest.State, TerritoryEpicorID = syncShiptoRequest.TerritoryEpicorID, VendorId = User.VendorId, }; dataService.Insert(ShipToToInsert); NewShipTo.IsRunning = false; await dialogService.ShowMessage("Exito", "Se inserto el registro con exito."); EditCustomer.RefreshShipTo(); await navigationService.Back(); #endregion } catch (Exception ex) { await dialogService.ShowMessage("Error", ex.Message); } }
async void EditarShipTo() { try { var connection = await netService.CheckConnectivity(); if (!connection.IsSuccess) { await dialogService.ShowMessage("Error", connection.Message); return; } var answer = await dialogService.ShowConfirm( "Confirmación", "¿Guardar cambios?"); if (!answer) { return; } if (string.IsNullOrEmpty(EditShipTo.ShipTo.ShipToName)) { await dialogService.ShowMessage( "Error", "Debes ingresar nombre de sucursal."); return; } if (string.IsNullOrEmpty(EditShipTo.ShipTo.Country)) { await dialogService.ShowMessage( "Error", "Debes seleccionar un pais."); return; } EditShipTo.IsRunning = true; var ShipToToUpdate = new SyncShiptoRequest { Address = EditShipTo.ShipTo.Address, City = EditShipTo.ShipTo.City, Company = EditShipTo.ShipTo.Company, Country = EditShipTo.ShipTo.Country, CustNum = EditShipTo.ShipTo.CustNum, CustomerId = EditShipTo.ShipTo.CustomerId, Email = EditShipTo.ShipTo.Email, PhoneNum = EditShipTo.ShipTo.PhoneNum, ShipToId = EditShipTo.ShipTo.ShipToId, ShipToName = EditShipTo.ShipTo.ShipToName, ShipToNum = EditShipTo.ShipTo.ShipToNum, SincronizadoEpicor = false, State = EditShipTo.ShipTo.State, TerritoryEpicorID = EditShipTo.ShipTo.TerritoryEpicorID, VendorId = User.VendorId, }; var url = Application.Current.Resources["URLAPI"].ToString(); var response = await apiService .PostMaster(url, "/api/ShipToes", ShipToToUpdate); if (!response.IsSuccess) { await dialogService.ShowMessage("Error", response.Message); return; } var syncShiptoRequest = (SyncShiptoRequest)response.Result; var ShipToToInsert = new ShipTo { Address = syncShiptoRequest.Address, City = syncShiptoRequest.City, Company = syncShiptoRequest.Company, Country = syncShiptoRequest.Country, CustNum = syncShiptoRequest.CustNum, CustomerId = syncShiptoRequest.CustomerId, Email = syncShiptoRequest.Email, PhoneNum = syncShiptoRequest.PhoneNum, ShipToId = syncShiptoRequest.ShipToId, ShipToName = syncShiptoRequest.ShipToName, ShipToNum = syncShiptoRequest.ShipToNum, SincronizadoEpicor = syncShiptoRequest.SincronizadoEpicor, State = syncShiptoRequest.State, TerritoryEpicorID = syncShiptoRequest.TerritoryEpicorID, VendorId = User.VendorId, }; dataService.Delete(EditShipTo.ShipTo); dataService.Insert(ShipToToInsert); EditShipTo.IsRunning = false; await dialogService.ShowMessage("Exito", "Se actualizo el registro con exito."); await navigationService.Back(); #endregion } catch (Exception ex) { await dialogService.ShowMessage("Error", ex.Message); } }