public List <VMMultiLocations> GetAllPassLocationsByVehicleType(string accessToken, string VehicleTypeCode, int CustomerVehiclePassId) { List <Location> lstLocations = new List <Location>(); List <VMMultiLocations> lstVMLocations = new List <VMMultiLocations>(); try { string baseUrl = Convert.ToString(App.Current.Properties["BaseURL"]); using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Add the Authorization header with the AccessToken. client.DefaultRequestHeaders.Add("Authorization", "bearer " + accessToken); // create the URL string. string url = "api/InstaOperator/getOPAPPGetAllPassLocationsByVehicleType?VehicleTypeCode=" + VehicleTypeCode + "&CustomerVehiclePassId=" + CustomerVehiclePassId; // make the request HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { string jsonString = response.Content.ReadAsStringAsync().Result; if (jsonString != null) { APIResponse apiResult = JsonConvert.DeserializeObject <APIResponse>(jsonString); if (apiResult.Result) { lstLocations = JsonConvert.DeserializeObject <List <Location> >(Convert.ToString(apiResult.Object)); if (lstLocations.Count > 0) { for (var i = 0; i < lstLocations.Count; i++) { VMMultiLocations objvm = new VMMultiLocations(); objvm.LocationID = lstLocations[i].LocationID; objvm.LocationCode = Convert.ToString(lstLocations[i].LocationCode); objvm.LocationName = Convert.ToString(lstLocations[i].LocationName); lstVMLocations.Add(objvm); } } } } } } } catch (Exception ex) { } return(lstVMLocations); }
private async void CheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e) { try { var resultbox = (CheckBox)sender; VMMultiLocations ob = resultbox.BindingContext as VMMultiLocations; if (resultbox.IsChecked) { Location objselected = new Location(); objselected.LocationID = ob.LocationID; objselected.LocationName = ob.LocationName; if (lstSelectedLocations.Count < 3) { labelSelectedStations.Text = labelSelectedStations.Text + "," + ob.LocationName.ToUpper(); lstSelectedLocations.Add(objselected); } else { resultbox.IsChecked = false; await DisplayAlert("Alert", "Maximum 3 stations only", "Ok"); } } else { if (lstSelectedLocations.Count > 0) { var item = lstSelectedLocations.SingleOrDefault(x => x.LocationID == ob.LocationID); if (item != null) { lstSelectedLocations.Remove(item); if (labelSelectedStations.Text.Contains(item.LocationName.ToUpper())) { labelSelectedStations.Text = labelSelectedStations.Text.Replace("," + item.LocationName.ToUpper(), string.Empty); } } } } } catch (Exception ex) { dal_Exceptionlog.InsertException(Convert.ToString(App.Current.Properties["apitoken"]), "Operator App", ex.Message, "MultiStationPassPage.xaml.cs", "", "CheckBox_CheckedChanged"); } }