public void AddCountry(Country country) { using (GarmentsContext context = new GarmentsContext()) { context.Countries.Add(country); context.SaveChanges(); } }
public void AddProvince(Province province) { using (GarmentsContext context = new GarmentsContext()) { context.Entry(province.Country).State = EntityState.Unchanged; context.Provinces.Add(province); context.SaveChanges(); } }
public void DeleteCountry(Country country) { using (GarmentsContext context = new GarmentsContext()) { Country found = context.Countries.Find(country.Id); context.Countries.Remove(found); context.SaveChanges(); } }
public void UpdateCountry(int idToSearch, Country country) { using (GarmentsContext context = new GarmentsContext()) { Country found = context.Countries.Find(idToSearch); if (!(string.IsNullOrWhiteSpace(country.Name))) { found.Name = country.Name; } found.Code = country.Code; context.SaveChanges(); } }