/// <summary> /// Posts the values. /// </summary> /// <param name="context">Context.</param> /// <param name="jobRequest">Job request.</param> public async System.Threading.Tasks.Task <List <Branch> > AsyncBranchLocator(BranchRequest BranchRequest) { List <Branch> branchList = new List <Branch>(); try { var baseAddress = new Uri(Constants.JobBaseAddress); var cookieContainer = new CookieContainer(); cookieContainer.Add(baseAddress, new Cookie("IsJobPage", "0")); CFNetworkHandler networkHandler = new CFNetworkHandler(); networkHandler.UseSystemProxy = true; networkHandler.CookieContainer = cookieContainer; string data = "{\"dto\":{\"Latitude\":" + "\"" + BranchRequest.Latitude + "\"" + "," + "\"Longitude\":" + "\"" + BranchRequest.Longitude + "\"" + "," + "\"MaxResults\":" + "\"" + BranchRequest.MaxResults + "\"" + "," + "\"Radius\":" + "\"" + BranchRequest.Radius + "\"" + "," + "\"Industry\":" + "\"" + BranchRequest.Industry + "\"" + "," + "\"RadiusUnits\":" + "\"" + BranchRequest.RadiusUnits + "\"" + "}}"; var _content = new StringContent(data, Encoding.UTF8, "application/json"); using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer }) using (var client = new HttpClient(handler)) { try { var httpResponse = await client.PostAsync(Constants.BranchLocator, _content); if (httpResponse.StatusCode == HttpStatusCode.OK) { string responseContent = await httpResponse.Content.ReadAsStringAsync(); dynamic responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseContent); dynamic jobitems = responseObj["Items"]; foreach (JObject jcontent in jobitems.Children <JObject>()) { Branch branch = new Branch(); branch = jcontent.ToObject <Branch>(); branchList.Add(branch); } return(branchList); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(branchList); }
#pragma warning disable RECS0165 // Asynchronous methods should return a Task instead of void private async void getBranchList() #pragma warning restore RECS0165 // Asynchronous methods should return a Task instead of void { NetworkStatus remoteHostStatus = Reachability.RemoteHostStatus(); if (remoteHostStatus == NetworkStatus.NotReachable) { var alert = UIAlertController.Create("Network Error", "Please check your internet connection", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); PresentViewController(alert, animated: true, completionHandler: null); return; } //BTProgressHUD.Show("Searching Branches...", -1, ProgressHUD.MaskType.Black); //Console.WriteLine("JobLocations ==> {0}",DbHelper.JobLocations); BranchRequest _branchRequest = new BranchRequest(); _branchRequest.Latitude = Constants.Latitude; _branchRequest.Longitude = Constants.Longitude; _branchRequest.Radius = ConfigManager.BLRadius; if (!string.IsNullOrEmpty(Constants.Latitude)) { _branchRequest.Latitude = Constants.Latitude; } if (!string.IsNullOrEmpty(Constants.Longitude)) { _branchRequest.Longitude = Constants.Longitude; } if (!string.IsNullOrEmpty(this.txtDistance.Text)) { String[] splitstring = txtDistance.Text.Split(' '); _branchRequest.Radius = splitstring[0]; } _branchRequest.RadiusUnits = "KM"; _branchRequest.Industry = "ALL"; _branchRequest.MaxResults = ConfigManager.BLMaxResultCount; ServiceManager jobService = new ServiceManager(); List <Branch> _branchList = await jobService.AsyncBranchLocator(_branchRequest); //Console.WriteLine(_branchList); BTProgressHUD.Dismiss(); Gai.SharedInstance.DefaultTracker.Send(DictionaryBuilder.CreateEvent("Branch Search", "BranchSearch_button_press", "AppEvent", null).Build()); Gai.SharedInstance.Dispatch(); // Manually dispatch the event immediately // just for demonstration // not much recommended AppDelegate appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate; UIStoryboard storyboard = UIStoryboard.FromName(appDelegate.storyboard, null); var _aBranchListVC = (BranchListVC)storyboard.InstantiateViewController("BranchListVC"); _aBranchListVC._branchList = _branchList; this.NavigationController.PushViewController(_aBranchListVC, true); }