public async Task <IActionResult> Add([FromBody] Applicant applicant) { Boolean t = false; List <Country> c = await RESTCountriesAPI.GetAllCountriesAsync(); for (int i = 0; i < c.Count; i++) { if (c[i].Name.ToUpper() == applicant.CountryOfOrigin.ToUpper()) { t = true; break; } } if (t == true) { await _repository.AddApplicant(applicant); return(CreatedAtAction(nameof(GetById), new { id = applicant.ApplicantId }, applicant)); } else { return(BadRequest("Please Enter correct Country")); } }
public async Task <IActionResult> Index() { _logger.LogInformation("Obteniendo los paises"); var listaPaises = (await RESTCountriesAPI.GetAllCountriesAsync()).Select(c => c.Name).ToList(); return(Ok(listaPaises)); }
public async Task <ActionResult> Index(string countryName) { var countries = await RESTCountriesAPI.GetAllCountriesAsync(); if (countries.Any(x => x.Name == countryName)) { return(RedirectToAction(nameof(Search), "Home", new { countryName })); } return(View()); }
//Осуществляет вывод информации, при смене выбранной страны в ListBoxe-e private async void SelectedItem(object sender, EventArgs e) { label10.Text = listBox1.SelectedIndex.ToString(); int index1 = Convert.ToInt32(label10.Text); List <Country> countries = await RESTCountriesAPI.GetAllCountriesAsync(); ListBox.ObjectCollection collection = new ListBox.ObjectCollection(listBox1); foreach (Country country in countries) { label1.Text = collection.Count.ToString(); collection.Add(country); //listBox1.DisplayMember = "Name"; label1.Text = collection.Count.ToString(); if (collection.IndexOf(country) == index1) { Strana.Text = country.Name; stran = Strana.Text; KodStrani.Text = country.Alpha2Code; Stolica.Text = country.Capital; try { double plosh = (double)country.Area; string newplosh = plosh.ToString("#,#", CultureInfo.InvariantCulture); Ploshad.Text = String.Format(CultureInfo.InvariantCulture, "{0:#,#}", newplosh + " км. кв."); } catch (Exception) { Ploshad.Text = String.Format(CultureInfo.InvariantCulture, "Площадь не известна!"); } 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(index1, true); }
//public List<Country> countriesNEW = new List<Country>(); // Использовать для проверки элементов в листе private async void textBox1_TextChanged(object sender, EventArgs e) { // Очищаем список. listBox1.Items.Clear(); //CountOfCountriey = 250; label1.Text = listBox1.Items.Count.ToString(); label1.Refresh(); valueCountry = textBox1.Text; if (string.IsNullOrWhiteSpace(textBox1.Text)) { List <Country> countries = await RESTCountriesAPI.GetAllCountriesAsync(); ListBox.ObjectCollection collection = new ListBox.ObjectCollection(listBox1); foreach (Country country in countries) { label1.Text = collection.Count.ToString(); collection.Add(country); //listBox1.DisplayMember = "Name"; label1.Text = collection.Count.ToString(); } } }
private async void Form1_Load(object sender, EventArgs e) { //Change this path for your own computer //string connectionString = @"Server=(localdb)\\mssqllocaldb;Database=testTaskDB;Trusted_Connection=True;MultipleActiveResultSets=true"; sqlConnection = new SqlConnection(connectionString); await sqlConnection.OpenAsync(); SqlDataReader sqlReader = null; SqlCommand command = new SqlCommand("SELECT * FROM [Countries]", sqlConnection); sqlReader = await command.ExecuteReaderAsync(); // **************************************************************************************************************** Основной код List <Country> countries = await RESTCountriesAPI.GetAllCountriesAsync(); ListBox.ObjectCollection collection = new ListBox.ObjectCollection(listBox1); textBox1.Focus(); int i = 0; foreach (Country country in countries) { collection.Add(country); //listBox1.Items.Add(country); //listBox1.DisplayMember = "Name"; SqlCommand command1 = new SqlCommand("INSERT INTO [Citiess] (Name) VALUES(@Name)", sqlConnection); SqlCommand command2 = new SqlCommand("INSERT INTO [Regions] (Name) VALUES(@Name)", sqlConnection); SqlCommand command3 = new SqlCommand("INSERT INTO [Countries] (Name, CountryCode, CapitalId, Area, Population, RegionId) VALUES(@Name, @CountryCode,@CapitalID, @Area, @Population, @RegionId)", sqlConnection); SqlCommand command4 = new SqlCommand("SELECT Citiess.Name FROM [Countries] INNER JOIN [Citiess] ON Countries.CapitalId = Cities.Id)", sqlConnection); SqlCommand command5 = new SqlCommand("INSERT INTO [Countries] (RegionId) VALUES (Countries.Id)", sqlConnection); command1.Parameters.AddWithValue("Name", country.Capital); command2.Parameters.AddWithValue("Name", country.Region); if (country.Name == null) { country.Name = "NONE"; command3.Parameters.AddWithValue("Name", country.Name); } else { command3.Parameters.AddWithValue("Name", country.Name); } command3.Parameters.AddWithValue("CountryCode", country.Alpha2Code); command3.Parameters.AddWithValue("CapitalId", i++); command3.Parameters.AddWithValue("Area", country.Area); command3.Parameters.AddWithValue("Population", country.Population); command3.Parameters.AddWithValue("RegionId", i++); //await command3.ExecuteNonQueryAsync(); //await command4.ExecuteNonQueryAsync(); //await command5.ExecuteNonQueryAsync(); //await command5.ExecuteNonQueryAsync(); //await command1.ExecuteNonQueryAsync(); //await command2.ExecuteNonQueryAsync(); } if (sqlConnection != null && sqlConnection.State != ConnectionState.Closed) { sqlConnection.Close(); } CountOfCountriey = collection.Count; }
private bool IsValidCountryCategory(UpdateApplicantModel applicant, string homeCountry) { var validCountries = RESTCountriesAPI.GetAllCountriesAsync().Result; return(validCountries.Exists(x => x.Name == homeCountry)); }