public void EditCity(int id, string name) { var city = _context.Cities.FirstOrDefault(x => x.Id == id); if (city != null) { city.Name = name; _context.Cities.Update(city); _context.SaveChanges(); } }
public bool Save() { return(_context.SaveChanges() >= 0); }
public static void EnsureSeedDataForContext(this CitiesDbContext context) { if (context.Cities.Any()) { return; } // init seed data var cities = new List <City>() { new City() { Name = "New York City", Description = "The one with that big park.", PointsOfInterest = new List <PointOfInterest>() { new PointOfInterest() { Name = "Central Park", Description = "The most visited urban park in the United States." }, new PointOfInterest() { Name = "Empire State Building", Description = "A 102-story skyscraper located in Midtown Manhattan." }, } }, new City() { Name = "Antwerp", Description = "The one with the cathedral that was never really finished.", PointsOfInterest = new List <PointOfInterest>() { new PointOfInterest() { Name = "Cathedral", Description = "A Gothic style cathedral, conceived by architects Jan and Pieter Appelmans." }, new PointOfInterest() { Name = "Antwerp Central Station", Description = "The the finest example of railway architecture in Belgium." }, } }, new City() { Name = "Paris", Description = "The one with that big tower.", PointsOfInterest = new List <PointOfInterest>() { new PointOfInterest() { Name = "Eiffel Tower", Description = "A wrought iron lattice tower on the Champ de Mars, named after engineer Gustave Eiffel." }, new PointOfInterest() { Name = "The Louvre", Description = "The world's largest museum." }, } } }; context.Cities.AddRange(cities); context.SaveChanges(); }