/// <summary> /// Processes the region population strats. /// </summary> /// <param name="regionPopulationStrats">The region population strats.</param> /// <param name="errors">The errors.</param> private void ProcessRegionPopulationStrats(RegionPopulationStrats regionPopulationStrats, IList <ImportError> errors) { try { if (errors.Any()) { return; } HospitalRegistryService.Save(regionPopulationStrats); } catch (Exception exc) { errors.Add(ImportError.Create(typeof(RegionPopulationStrats).Name, regionPopulationStrats.RegionID.ToString(), (exc.InnerException ?? exc).Message)); } }
/// <summary> /// Processes the region. /// </summary> /// <param name="region">The region.</param> /// <param name="errors">The errors.</param> private void ProcessRegion(CustomRegion region, IList <ImportError> errors) { var criteria = PredicateBuilder.False <CustomRegion>().Or(r => r.ImportRegionId == region.ImportRegionId); var stateCriteria = PredicateBuilder.False <CustomRegion>(); CurrentStatesBeingManaged.ToList().ForEach(abbr => stateCriteria = stateCriteria.Or(r => region.State.ToUpper() == abbr.ToUpper())); criteria = criteria.And(stateCriteria); var reg = GetExistingRegion(criteria); if (reg != null) { // if the found region is custom type, overwrite it in the database with the attributes being imported region.Code = region.Code; reg.Name = region.Name; reg.State = region.State; reg.ImportRegionId = region.ImportRegionId; } else { reg = region; } if (CurrentStatesBeingManaged.All(s => s.ToLower() != reg.State.ToLower())) { var errorMessage = string.Format( "The region \"{0}\" can't be added because it is not in the correct geo context state. CMS NUMBER: {0}", reg.Name); errors.Add(ImportError.Create("CustomRegion", reg.Name, errorMessage)); return; } if (errors.Any()) { return; } HospitalRegistryService.Save(reg); Events.GetEvent <EntityImportedEvent <CustomRegion> >().Publish(reg); }