public async Task <IActionResult> Edit(int id, [Bind("Id,CountryName,Gdp,Population")] Countires countires) { if (id != countires.Id) { return(NotFound()); } if (await findCountriesWithTheSameName(countires) != null) { ModelState.AddModelError(String.Empty, "Country with this name already exists"); } if (ModelState.IsValid) { try { _context.Update(countires); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CountiresExists(countires.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(countires)); }
private void WriteCountryToWorksheet(Countires country, IXLWorksheet worksheet) { int indexOfFirstCountryCell = 3; worksheet.Cell(2, indexOfFirstCountryCell).Value = country.CountryName; worksheet.Cell(2, indexOfFirstCountryCell + 1).Value = country.Gdp; worksheet.Cell(2, indexOfFirstCountryCell + 2).Value = country.Population; }
private Countires CreateCountry(IXLWorksheet worksheet) { Countires country = new Countires(); var row = RowWithIndexInWorksheet(worksheet, 0, 1); country.CountryName = row.Cell(3).Value.ToString(); country.Gdp = Decimal.Parse(row.Cell(4).Value.ToString()); country.Population = Double.Parse(row.Cell(5).Value.ToString()); return country; }
public async Task <IActionResult> Create([Bind("Id,CountryName,Gdp,Population")] Countires countires) { if (await findCountriesWithTheSameName(countires) != null) { ModelState.AddModelError(String.Empty, "Country with this name already exists"); } if (ModelState.IsValid) { _context.Add(countires); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(countires)); }
public async Task <Countires> findCountriesWithTheSameName(Countires countires) { return(await _context.Countires.FirstOrDefaultAsync(c => c.CountryName == countires.CountryName)); }
private void AttachExistingCountryToAgency(SpaceAgencies agency, Countires country) { agency.HeadquarterCountry = country; agency.HeadquarterCountryId = country.Id; }