public async Task <IActionResult> Edit(int id, [Bind("Id,Name,CountryCode,District,Population")] City city) { if (id != city.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(city); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CityExists(city.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CountryCode"] = new SelectList(_context.Country, "Code", "Code", city.CountryCode); return(View(city)); }
public async Task <ActionResult> AddorEdit([Bind("Name, CountryCode, District, Population")] City city) { var context = new worldContext(); var currentCity = context.City.Where(c => c.Name.Equals(city.Name)).FirstOrDefault(); if (ModelState.IsValid) { if (currentCity == null) { context.Add(city); } else { currentCity.Name = city.Name; currentCity.CountryCode = city.CountryCode; currentCity.District = city.District; currentCity.Population = city.Population; context.Update(currentCity); } await context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(city)); }
public async Task <IActionResult> Edit(City city) { if (ModelState.IsValid) { _context.Update(city); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(string id, [Bind("Code,Name,Region,NationalFlag")] Country country) { if (id != country.Code) { return(NotFound()); } if (ModelState.IsValid) { try { country.NationalFlag = "Images/Default.png"; _context.Update(country); await _context.SaveChangesAsync(); } catch { return(RedirectToAction("Error", "Home")); } return(RedirectToAction(nameof(Index))); } return(View(country)); }
public async Task <ActionResult> AddorEdit([Bind("Code, Name, Region, NationalFlag")] Country country) { var context = new worldContext(); var currentCountry = context.Country.Find(country.Code); if (ModelState.IsValid) { if (currentCountry == null) { context.Add(country); } else { currentCountry.Name = country.Name; currentCountry.Region = country.Region; currentCountry.NationalFlag = country.NationalFlag; context.Update(currentCountry); } await context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(country)); }