public override Region GetTopLevelRegion() { using (var transaction = new TransactionScope(_configuration)) { var store = new RegionDataStore(transaction); IList <Region> regions = store.FindByParentRegion(string.Empty); if (regions.Count == 0) { return(null); } return(regions.First()); } }
public override bool IsRegionUnique(Region region) { if (region == null) { throw new ArgumentNullException("region"); } bool unique = false; // A region must be unique within an parent region. using (var transaction = new TransactionScope(_configuration)) { var ds = new RegionDataStore(transaction); IList <Region> siblings = ds.FindByParentRegion(region.ParentRegion.Id); Region match = siblings.FirstOrDefault(x => x.Name.Equals(region.Name)); if (match == null) { unique = true; } } return(unique); }
public override IList <Site> GetAllSitesByRegion(Region region, bool recursive) { using (var transaction = new TransactionScope(_configuration)) { var sDs = new SiteDataStore(transaction); IList <Site> sites = sDs.FindAllByRegion(region.Id); if (recursive) { // Find children of this parent region. var rDs = new RegionDataStore(transaction); IList <Region> childRegions = rDs.FindByParentRegion(region.Id); foreach (Region subRegion in childRegions) { IList <Site> subSites = GetAllSitesByRegion(subRegion, true); foreach (Site subSite in subSites) { sites.Add(subSite); } } } return(sites); } }