/// <summary> /// Returns site based on domain /// </summary> /// <param name="host">The host.</param> /// <returns></returns> public static SiteCache GetSiteByDomain(string host) { int siteId = 0; if (_siteDomains.TryGetValue(host, out siteId)) { return(Read(siteId)); } using (var rockContext = new RockContext()) { Rock.Model.SiteDomainService siteDomainService = new Rock.Model.SiteDomainService(rockContext); Rock.Model.SiteDomain siteDomain = siteDomainService.GetByDomain(host); if (siteDomain == null) { siteDomain = siteDomainService.GetByDomainContained(host); } if (siteDomain != null) { _siteDomains.AddOrUpdate(host, siteDomain.SiteId, (k, v) => siteDomain.SiteId); return(Read(siteDomain.SiteId)); } } return(null); }
/// <summary> /// To the model. /// </summary> /// <param name="value">The value.</param> /// <returns></returns> public static SiteDomain ToModel(this SiteDomainDto value) { SiteDomain result = new SiteDomain(); value.CopyToModel(result); return(result); }
/// <summary> /// Copies the properties from another SiteDomain object to this SiteDomain object /// </summary> /// <param name="target">The target.</param> /// <param name="source">The source.</param> public static void CopyPropertiesFrom(this SiteDomain target, SiteDomain source) { target.IsSystem = source.IsSystem; target.SiteId = source.SiteId; target.Domain = source.Domain; target.Id = source.Id; target.Guid = source.Guid; }
/// <summary> /// Clones this SiteDomain object to a new SiteDomain object /// </summary> /// <param name="source">The source.</param> /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param> /// <returns></returns> public static SiteDomain Clone(this SiteDomain source, bool deepCopy) { if (deepCopy) { return(source.Clone() as SiteDomain); } else { var target = new SiteDomain(); target.CopyPropertiesFrom(source); return(target); } }
/// <summary> /// Copies the properties from another SiteDomain object to this SiteDomain object /// </summary> /// <param name="target">The target.</param> /// <param name="source">The source.</param> public static void CopyPropertiesFrom(this SiteDomain target, SiteDomain source) { target.Id = source.Id; target.Domain = source.Domain; target.IsSystem = source.IsSystem; target.SiteId = source.SiteId; target.CreatedDateTime = source.CreatedDateTime; target.ModifiedDateTime = source.ModifiedDateTime; target.CreatedByPersonAliasId = source.CreatedByPersonAliasId; target.ModifiedByPersonAliasId = source.ModifiedByPersonAliasId; target.Guid = source.Guid; target.ForeignId = source.ForeignId; }
/// <summary> /// Returns site based on domain /// </summary> /// <param name="id"></param> public static SiteCache GetSiteByDomain(string host) { SiteCache site = null; string cacheKey = "Rock:DomainSites"; ObjectCache cache = MemoryCache.Default; Dictionary <string, int> sites = cache[cacheKey] as Dictionary <string, int>; if (sites == null) { sites = new Dictionary <string, int>(); } // look in cache if (sites.ContainsKey(host)) { site = Rock.Web.Cache.SiteCache.Read(sites[host]); } else { // get from database Rock.Model.SiteDomainService siteDomainService = new Rock.Model.SiteDomainService(); Rock.Model.SiteDomain siteDomain = siteDomainService.GetByDomain(host); if (siteDomain == null) { siteDomain = siteDomainService.GetByDomainContained(host); } if (siteDomain != null) { return(SiteCache.Read(siteDomain.SiteId)); } } return(site); }
/// <summary> /// Instantiates a new DTO object from the entity /// </summary> /// <param name="siteDomain"></param> public SiteDomainDto(SiteDomain siteDomain) { CopyFromModel(siteDomain); }
/// <summary> /// To the dto. /// </summary> /// <param name="value">The value.</param> /// <returns></returns> public static SiteDomainDto ToDto(this SiteDomain value) { return(new SiteDomainDto(value)); }