public override void CreateRegion(Region region)
        {
            if (region.RegionType == null)
            {
                throw new ArgumentNullException("region", "RegionType is null");
            }
            if (string.IsNullOrEmpty(region.Name))
            {
                throw new ProviderException("Region name cannot be empty or null.");
            }
            if (region.Name.IndexOf(',') > 0)
            {
                throw new ArgumentException("Region names cannot contain commas.", "region");
            }

            using (var transaction = new TransactionScope(_configuration))
            {
                if (!RegionTypeExists(region.RegionType))
                {
                    CreateRegionType(region.RegionType);
                }

                var rDs = new RegionDataStore(transaction);
                rDs.Insert(region);
                transaction.Commit();
            }
        }
 public override Region GetRegionById(string id)
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var store = new RegionDataStore(transaction);
         return(store.FindByKey(id));
     }
 }
 public override IList <Region> GetAllRegionsByRegionType(RegionType regionType)
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var rDs = new RegionDataStore(transaction);
         return(rDs.FindAllByRegionType(regionType));
     }
 }
 public override IList <Region> GetAllRegionsByName(string name)
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var store = new RegionDataStore(transaction);
         return(store.FindAllByName(name));
     }
 }
 public override IList <Region> GetAllRegionsBelow(Region region)
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var store = new RegionDataStore(transaction);
         return(store.FindAllBelow(region));
     }
 }
 public override void UpdateRegion(Region region)
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var rDs = new RegionDataStore(transaction);
         rDs.Update(region);
         transaction.Commit();
     }
 }
 public override IList <Region> GetAllRegions()
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var            store   = new RegionDataStore(transaction);
         IList <Region> regions = store.FindAll();
         // Order by breadcrumb.
         IEnumerable <Region> ordered = regions.OrderBy(x => x.Breadcrumb);
         return(ordered.ToList());
     }
 }
 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 void DeleteRegion(Region region)
        {
            using (var transaction = new TransactionScope(_configuration))
            {
                var rDs = new RegionDataStore(transaction);
                region.Deleted = true;
                region.Name   += DateTimeHelper.GetCurrentTimestamp();

                DeleteSubRegion(region);

                rDs.Update(region);
                transaction.Commit();
            }
        }
        public override bool RegionExists(Region region)
        {
            using (var transaction = new TransactionScope(_configuration))
            {
                var    rDs = new RegionDataStore(transaction);
                Region r   = rDs.FindByName(region.Name);

                if (r != null)
                {
                    return(true);
                }
            }
            return(false);
        }
 public void DeleteSubRegion(Region region)
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var            rDs      = new RegionDataStore(transaction);
         IList <Region> children = rDs.FindAllBelow(region);
         foreach (Region child in children)
         {
             child.Deleted = true;
             child.Name   += DateTimeHelper.GetCurrentTimestamp();
             rDs.Update(child);
         }
         transaction.Commit();
     }
 }
        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);
     }
 }