public static void UpdateSeedServiceAreaInfo(this DbAppContext context, ServiceArea serviceAreaInfo) { // Adjust the district. int ministry_district_id = serviceAreaInfo.District.MinistryDistrictID; var exists = context.Districts.Any(a => a.MinistryDistrictID == ministry_district_id); if (exists) { District district = context.Districts.First(a => a.MinistryDistrictID == ministry_district_id); serviceAreaInfo.District = district; } else { serviceAreaInfo.District = null; } ServiceArea serviceArea = context.GetServiceAreaByMinistryServiceAreaId(serviceAreaInfo.MinistryServiceAreaID); if (serviceArea == null) { context.ServiceAreas.Add(serviceAreaInfo); } else { serviceArea.Name = serviceAreaInfo.Name; serviceArea.StartDate = serviceAreaInfo.StartDate; serviceArea.District = serviceAreaInfo.District; } }