예제 #1
0
        public IActionResult Create(City newCity)
        {
            if (ModelState.IsValid)
            {
                _contextCity.City.Add(newCity);
                _contextCity.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
예제 #2
0
        public void AddCountry(Country country)
        {
            Country countryToAdd = context.Countries.Find(country.Code);

            if (countryToAdd == null)
            {
                context.Countries.Add(country);
                context.SaveChanges();
            }
            else
            {
                throw new ArgumentException("Country with that Code doesn't exist");
            }
        }
예제 #3
0
        public void AddCity(City city)
        {
            City cityToAdd = context.Cities.Find(city.Id);

            if (cityToAdd == null)
            {
                context.Cities.Add(city);
                context.SaveChanges();
            }
            else
            {
                throw new ArgumentException("City with that Id doesn't exist");
            }
        }
        public async Task CreateCityAsync(City city)
        {
            using (var context = new worldContext())
            {
                await context.City.AddAsync(city);

                context.SaveChanges();
            }
        }
 public async Task UpdateCityAsync(City city)
 {
     await Task.Run(() =>
     {
         using (var context = new worldContext())
         {
             context.City.Update(city);
             context.SaveChanges();
         }
     });
 }
예제 #6
0
        public IActionResult Create(Country newCountry)
        {
            if (ModelState.IsValid)
            {
                _context.Country.Add(newCountry);
            }

            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
 public async Task UpdateCountryAsync(Country country)
 {
     await Task.Run(() =>
     {
         using (var context = new worldContext())
         {
             context.Country.Update(country);
             context.SaveChanges();
         }
     });
 }
예제 #8
0
 public IActionResult DeleteConfirmed(int id)
 {
     try
     {
         var city = _context.City.Find(id);
         _context.City.Remove(city);
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     catch {
         return(RedirectToAction("Error", "Home"));
     }
 }
예제 #9
0
        // GET: CountryController/Delete/5
        public ActionResult Delete(string id)
        {
            var context = new worldContext();

            if (id == null)
            {
                return(NotFound());
            }
            var country = context.Country.FirstOrDefault(c => c.Code.Equals(id));

            context.Country.Remove(country);
            context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
 public async Task RemoveCityByIdAsync(int id)
 {
     await Task.Run(() =>
     {
         using (var context = new worldContext())
         {
             var cityToDelete = new City {
                 Id = id
             };
             context.City.Attach(cityToDelete);
             context.City.Remove(cityToDelete);
             context.SaveChanges();
         }
     });
 }
 public async Task RemoveCountryByCodeAsync(string code)
 {
     await Task.Run(() =>
     {
         using (var context = new worldContext())
         {
             var countryToDelete = new Country {
                 Code = code
             };
             context.Country.Attach(countryToDelete);
             context.Country.Remove(countryToDelete);
             context.SaveChanges();
         }
     });
 }
예제 #12
0
 public ActionResult Delete(int?id)
 {
     try
     {
         var context = new worldContext();
         if (id == 0)
         {
             return(NotFound());
         }
         var city = context.City.FirstOrDefault(c => c.Id == id);
         context.City.Remove(city);
         context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
        public IActionResult Create(Country country)
        {
            if (ModelState.IsValid)
            {
                _db.Country.Add(country);
                _db.SaveChanges();
                return(RedirectToAction("Detail", country));
            }

            var continentlist = _db.Country.Select(c => c.Continent).Distinct().ToList();

            continentlist.Insert(0, "Select...");
            ViewBag.ListOfContinents = continentlist;

            var regionlist = _db.Country.Select(c => c.Region).Distinct().ToList();

            regionlist.Insert(0, "Select...");
            ViewBag.ListOfRegions = regionlist;

            return(View());
        }