public City DeleteCity(int id) { using (PropertyHubContext context = new PropertyHubContext()) { City found = context.Find <City>(id); context.Remove(found); context.SaveChanges(); return(found); } }
public City UpdateCity(int idToSearch, City city) { using (PropertyHubContext context = new PropertyHubContext()) { context.Entry(city.Province).State = EntityState.Unchanged; City found = context.Find <City>(idToSearch); found.Name = (!string.IsNullOrWhiteSpace(city.Name)) ? city.Name : found.Name; found.Province = (city.Province != null && city.Province.Id > 0) ? city.Province : found.Province; context.SaveChanges(); return(found); } }
public Country UpdateCountry(int idToSearch, Country country) { using (PropertyHubContext context = new PropertyHubContext()) { Country found = context.Find <Country>(idToSearch); //context.Update(country); if (!string.IsNullOrWhiteSpace(country.Name)) { found.Name = country.Name; } if (country.Code != null && country.Code > 0) { found.Code = country.Code; } context.SaveChanges(); return(found); } }