-
-
Save harvzor/c576864a19cb7ca18320 to your computer and use it in GitHub Desktop.
Queries the Umbraco database and returns a list of either all domains, or all domains associated with a particular node ID.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Represents a domain | |
/// </summary> | |
public class Domain | |
{ | |
/// <summary> | |
/// Gets the unique domain id | |
/// </summary> | |
public int DomainId { get; set; } | |
/// <summary> | |
/// Gets the name of the Domain | |
/// </summary> | |
public string Name { get; set; } | |
/// <summary> | |
/// Gets the root node id where this domain is applied | |
/// </summary> | |
public int RootNodeId { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using umbraco.BusinessLogic; | |
// Original: https://gist.github.com/florisrobbemont/5155690#file-domain-cs-L10 | |
public class Domains : Queries | |
{ | |
private static Domain PrepareDomain(umbraco.cms.businesslogic.web.Domain umbracoDomain) | |
{ | |
return new Domain | |
{ | |
DomainId = umbracoDomain.Id, | |
Name = umbracoDomain.Name, | |
RootNodeId = umbracoDomain.RootNodeId | |
}; | |
} | |
private static List<Domain> PrepareDomains(List<umbraco.cms.businesslogic.web.Domain> umbracoDomains) | |
{ | |
var domains = new List<Domain>(); | |
foreach (var domain in umbracoDomains) | |
{ | |
domains.Add(PrepareDomain(domain)); | |
} | |
return domains; | |
} | |
public static List<Domain> GetUmbracoDomains() | |
{ | |
var sqlHelper = Application.SqlHelper; | |
var result = new List<umbraco.cms.businesslogic.web.Domain>(); | |
using (var dr = sqlHelper.ExecuteReader("SELECT id, domainName, domainRootStructureID as RootNodeId from umbracoDomains")) | |
{ | |
while (dr.Read()) | |
{ | |
var domainId = dr.GetInt("id"); | |
result.Add(new umbraco.cms.businesslogic.web.Domain(domainId)); | |
} | |
} | |
return PrepareDomains(result); | |
} | |
public static List<Domain> GetUmbracoDomainsById(int id) | |
{ | |
var sqlHelper = Application.SqlHelper; | |
var result = new List<umbraco.cms.businesslogic.web.Domain>(); | |
using (var dr = sqlHelper.ExecuteReader("SELECT id, domainName, domainRootStructureID as RootNodeId from umbracoDomains WHERE domainRootStructureID = " + id)) | |
{ | |
while (dr.Read()) | |
{ | |
var domainId = dr.GetInt("id"); | |
result.Add(new umbraco.cms.businesslogic.web.Domain(domainId)); | |
} | |
} | |
return PrepareDomains(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment