public async Task <IActionResult> GetFlag(string country) { _logger.LogInformation($"Buscando la bandera del pais {country}"); byte[] bytes; try { var flag = (await RESTCountriesAPI.GetCountriesByNameContainsAsync(country)).Select(x => x.Flag).FirstOrDefault(); using (WebClient client = new WebClient()) { client.DownloadFileAsync(new Uri(flag), @"c:\tmp\flag.svg"); var svgString = flag; bytes = Encoding.UTF8.GetBytes(flag); var svg = Encoding.UTF8.GetString(bytes); } return(Ok(bytes)); } catch (Exception e) { _logger.LogWarning($"No se consiguio ninguna bandera, error {e}"); return(NotFound()); } }
public async Task <IActionResult> Post([FromBody] string country) { try { var paisNombre = (await RESTCountriesAPI.GetCountriesByNameContainsAsync(country)).FirstOrDefault(); Country paisPost = new() { Name = paisNombre.Name, Alpha2Code = paisNombre.Alpha2Code, Alpha3Code = paisNombre.Alpha3Code, Capital = paisNombre.Capital, NativeName = paisNombre.NativeName, Region = paisNombre.Region }; _context.Add(paisPost); await _context.SaveChangesAsync(); return(Created("", paisPost)); } catch (Exception e) { _logger.LogWarning($"No se consiguio ninguna pais {country}, error {e}"); return(NotFound()); } }
// Filter by country name public async Task <List <CountryShort> > GetCountries(string filter) { List <Country> countries = await RESTCountriesAPI.GetCountriesByNameContainsAsync(filter); var list = from item in countries select new CountryShort { Name = item.Name, Alpha2Code = item.Alpha2Code, Flag = item.Flag }; return(list.ToList()); }
public async Task <IActionResult> Index(string busqueda) { _logger.LogInformation($"Buscando el pais {busqueda}"); try { var pais = (await RESTCountriesAPI.GetCountriesByNameContainsAsync(busqueda)).FirstOrDefault(); return(Ok(pais)); } catch (Exception e) { _logger.LogWarning($"No se consiguio ningun pais con la palabra{busqueda}, error {e}"); return(NotFound()); } }
//Осуществляется проверка на введенные данные и попытка найти заданную страну public async void TRYING() { RepeatFindCountry: if (CountOfCountriey == 250) { //List<Country> countries = await RESTCountriesAPI.GetAllCountriesAsync(); //ListBox.ObjectCollection collection = new ListBox.ObjectCollection(listBox1); try { if (textBox1.Text != "") { //valueCountry = textBox1.Text; listBox1.Items.Clear(); List <Country> countries = await RESTCountriesAPI.GetCountriesByNameContainsAsync(textBox1.Text); ListBox.ObjectCollection collection = new ListBox.ObjectCollection(listBox1); foreach (Country country in countries) { collection.Add(country); //listBox1.DisplayMember = "Name"; label1.Text = collection.Count.ToString(); //Передача данных по стране Strana.Text = country.Name; stran = Strana.Text; KodStrani.Text = country.Alpha2Code; Stolica.Text = country.Capital; double plosh = (double)country.Area; string newplosh = plosh.ToString("#,#", CultureInfo.InvariantCulture); Ploshad.Text = String.Format(CultureInfo.InvariantCulture, "{0:#,#}", newplosh + " км. кв."); int Nasel = (int)country.Population; string newNasel = Nasel.ToString("#,#", CultureInfo.InvariantCulture); Naselenie.Text = String.Format(CultureInfo.InvariantCulture, "{0:#,#}", newNasel + " человек"); RegionStrani.Text = country.Region; } listBox1.Items.Clear(); listBox1.Update(); foreach (Country country in countries) { label1.Text = (collection.Count).ToString(); listBox1.Items.Add(country); } listBox1.SetSelected(0, true); } else { //List<Country> countries = await RESTCountriesAPI.GetAllCountriesAsync(); //ListBox.ObjectCollection collection = new ListBox.ObjectCollection(listBox1); //MessageBox.Show("Введите страну!", "Ошибка", MessageBoxButtons.OK); } } catch { Strana.ResetText(); KodStrani.ResetText(); Stolica.ResetText(); Ploshad.ResetText(); Naselenie.ResetText(); RegionStrani.ResetText(); MessageBox.Show("Cтрана не найдена. Проверьте правильность введенных данных!", "Ошибка", MessageBoxButtons.OK); textBox1.Clear(); goto RepeatFindCountry; } } //else CountOfCountriey = 251; }