public static void AddOrUpdate(Location location) { using (var connection = new ReferenceDataEntities()) { Location oldValue = connection.Locations.FirstOrDefault(x => x.Id == location.Id); if (oldValue != null) { connection.Entry(oldValue).CurrentValues.SetValues(location); connection.SaveChanges(); } else { connection.Locations.Add(location); connection.SaveChanges(); } } }
public void AddOrUpdate(Country country) { using (var connection = new ReferenceDataEntities()) { Country oldValue = connection.Countries.FirstOrDefault(x => x.Id == country.Id); if (oldValue != null) { connection.Entry(oldValue).CurrentValues.SetValues(country); connection.SaveChanges(); } else { connection.Countries.Add(country); connection.SaveChanges(); } } }
public User AddOrUpdate(User user) { using (var connection = new ReferenceDataEntities()) { User oldValue = connection.Users.FirstOrDefault(x => x.Id == user.Id); if (oldValue != null) { connection.Entry(oldValue).CurrentValues.SetValues(user); connection.SaveChanges(); return null; } else { connection.Users.Add(user); connection.SaveChanges(); return user; } } }