public override IList <Site> GetSitesByRegionType(RegionType regionType)
        {
            IList <Region> regions = GetAllRegionsByRegionType(regionType);

            using (var transaction = new TransactionScope(_configuration))
            {
                IList <Site> sites = null;
                foreach (Region region in regions)
                {
                    var          sDs      = new SiteDataStore(transaction);
                    IList <Site> subSites = sDs.FindAllByRegion(region.Id);
                    if (sites == null)
                    {
                        sites = subSites;
                    }
                    else
                    {
                        foreach (Site site in subSites)
                        {
                            sites.Add(site);
                        }
                    }
                }
                return(sites);
            }
        }
 public override IList <Site> GetAllSites()
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var store = new SiteDataStore(transaction);
         return(store.FindAll());
     }
 }
 public override Site GetSiteByLikeName(string siteName)
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var sDs = new SiteDataStore(transaction);
         return(sDs.FindByName(siteName));
     }
 }
 public override IList <Site> GetSitesBySiteName(string siteName)
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var          sDs   = new SiteDataStore(transaction);
         IList <Site> sites = sDs.FindAllByName(siteName);
         return(sites);
     }
 }
 public override void UpdateSite(Site site)
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var sDs = new SiteDataStore(transaction);
         sDs.Update(site);
         transaction.Commit();
     }
 }
 public override Site GetSiteByName(string siteName)
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var          sDs   = new SiteDataStore(transaction);
         IList <Site> sites = sDs.FindAllByName(siteName);
         return(sites.SingleOrDefault(x => x.Name.Equals(siteName, StringComparison.CurrentCultureIgnoreCase)));
     }
 }
        public override Site GetSiteById(string siteId)
        {
            using (var transaction = new TransactionScope(_configuration))
            {
                var  sDs  = new SiteDataStore(transaction);
                Site site = sDs.FindByKey(siteId);

                return(site.Deleted ? null : site);
            }
        }
 public override void DeleteSite(Site site)
 {
     using (var transaction = new TransactionScope(_configuration))
     {
         var sDs = new SiteDataStore(transaction);
         site.Deleted = true;
         site.Name   += DateTimeHelper.GetCurrentTimestamp();
         sDs.Update(site);
         transaction.Commit();
     }
 }
 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);
     }
 }
        public override void CreateSite(Site site)
        {
            if (site.Region == null)
            {
                throw new ArgumentNullException("site", "Region is null");
            }
            if (site.SiteType == null)
            {
                throw new ArgumentNullException("site", "SiteType is null");
            }
            if (string.IsNullOrEmpty(site.Name))
            {
                throw new ProviderException("Site name cannot be empty or null.");
            }
            if (site.Name.IndexOf(',') > 0)
            {
                throw new ArgumentException("Site names cannot contain commas.");
            }
            if (GetSiteByName(site.Name) != null)
            {
                throw new ProviderException("Site name already exists.");
            }

            using (var transaction = new TransactionScope(_configuration))
            {
                if (!RegionExists(site.Region))
                {
                    CreateRegion(site.Region);
                }
                else
                {
                    site.Region = GetRegionByName(site.Region.Name);
                }

                if (!SiteTypeExists(site.SiteType))
                {
                    CreateSiteType(site.SiteType);
                }
                else
                {
                    site.SiteType = GetSiteTypeByName(site.SiteType.Name);
                }

                //if (site.PhysicalAddress == null || string.IsNullOrEmpty(site.PhysicalAddress.Address1))
                //    site.PhysicalAddress = new Address.Address();
                //if (site.PostalAddress == null || string.IsNullOrEmpty(site.PostalAddress.Address1))
                //    site.PostalAddress = new Address.Address();
                if (site.PhysicalAddress != null)
                {
                    if (string.IsNullOrEmpty(site.PhysicalAddress.Id))
                    {
                        if (!string.IsNullOrEmpty(site.PhysicalAddress.Address1))
                        {
                            Address currentAddress = AddressManager.GetAddressByDetails(site.PhysicalAddress.Address1,
                                                                                        site.PhysicalAddress.Address2,
                                                                                        site.PhysicalAddress.Suburb,
                                                                                        site.PhysicalAddress.Postcode,
                                                                                        site.PhysicalAddress.State);
                            if (currentAddress == null)
                            {
                                AddressManager.CreateAddress(site.PhysicalAddress);
                            }
                            else
                            {
                                site.PhysicalAddress = currentAddress;
                            }
                        }
                    }
                }
                if (site.PostalAddress != null)
                {
                    if (string.IsNullOrEmpty(site.PostalAddress.Id))
                    {
                        if (!string.IsNullOrEmpty(site.PostalAddress.Address1))
                        {
                            Address currentAddress = AddressManager.GetAddressByDetails(site.PostalAddress.Address1,
                                                                                        site.PostalAddress.Address2,
                                                                                        site.PostalAddress.Suburb,
                                                                                        site.PostalAddress.Postcode,
                                                                                        site.PostalAddress.State);
                            if (currentAddress == null)
                            {
                                AddressManager.CreateAddress(site.PostalAddress);
                            }
                            else
                            {
                                site.PostalAddress = currentAddress;
                            }
                        }
                    }
                }

                var ptDs = new SiteDataStore(transaction);
                ptDs.Insert(site);
                transaction.Commit();
            }
        }