/// <summary> /// creates a new tab when a item from the CBox is selected /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CbCountry_SelectionChanged(object sender, SelectionChangedEventArgs e) { Country selected; try { selected = (Country)CbCountry.SelectedItem; if (selected == null || CbCountry.SelectedIndex == 0) { return; } if (!network) { selected = dataService.QueryCountry(selected.Alpha3Code); } //creates the UserControl var newTab = new ShowCountryDetails(selected); //adds the selected item name(country) and the usercontrol page to the viewModel to be presented in the tab CountryTab tab = new CountryTab(selected.Name, newTab); CountryMainViewModel.AddTab(tab); CountryTabs.SelectedItem = tab; } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.StackTrace); } }
public string GetCountryList() { string stringData = null; string tid = hadc.GetTokenId(); var response1 = string.Empty; CountryRequest cf = new CountryRequest(); cf.ClientId = ClientId; cf.TokenId = tid; cf.EndUserIp = ip.Replace(" ", ""); try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(BaseUriUpToCityData); MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json"); client.DefaultRequestHeaders.Accept.Add(contentType); var contentData = new StringContent(JsonConvert.SerializeObject(cf), System.Text.Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync("rest/CountryList", contentData).Result; stringData = response.Content.ReadAsStringAsync().Result; string str = stringData; var obj = JsonConvert.DeserializeObject <countrys>(str); Console.WriteLine(obj.Countrylist); int status = obj.Status; if (status == 1) { string countryListData = obj.Countrylist; XDocument doc = XDocument.Parse(countryListData); var CountryCodes = from service in doc.Descendants("Country") select(string) service.Element("Code"); var CountryNames = from service in doc.Descendants("Country") select(string) service.Element("Name"); CountryTab ct = new CountryTab(); foreach (var item in CountryCodes.Zip(CountryNames, (a, b) => new { A = a, B = b })) { var a = item.A; var b = item.B; ct.CountryCode = a; ct.CountryName = b; hotelCity.CountryTabs.Add(ct); hotelCity.SaveChanges(); } } } catch (WebException ex) { ViewBag.Ex = ex; } return(stringData); }
private void Hyperlink_Click(object sender, RoutedEventArgs e) { SQLService fast = new SQLService(); Hyperlink hp = (Hyperlink)e.Source; var search = fast.QueryCountry(hp.DataContext.ToString()); ShowCountryDetails border = new ShowCountryDetails(search); CountryTab newTab = new CountryTab(search.Name, border); CountryMainViewModel.AddTab(newTab); }