Created
March 13, 2013 20:09
-
-
Save florisrobbemont/5155690 to your computer and use it in GitHub Desktop.
Umbraco Get All Domains
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 language for the Domain | |
/// </summary> | |
public Language Language { 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
private void PrepareDomains() | |
{ | |
Domains = new List<Domain>(); | |
var umbracoDomains = GetUmbracoDomains(); | |
foreach (var domain in umbracoDomains) | |
{ | |
Domains.Add(new Domain | |
{ | |
DomainId = domain.Id, | |
Name = domain.Name, | |
RootNodeId = domain.RootNodeId, | |
Language = new Language | |
{ | |
CultureCode = domain.Language.CultureAlias, | |
FriendlyName = domain.Language.FriendlyName, | |
LanguageId = domain.Language.id | |
} | |
}); | |
} | |
} | |
private static IEnumerable<umbraco.cms.businesslogic.web.Domain> GetUmbracoDomains() | |
{ | |
var sqlHelper = Application.SqlHelper; | |
var result = new List<umbraco.cms.businesslogic.web.Domain>(); | |
using (var dr = sqlHelper.ExecuteReader("select id, domainName from umbracoDomains")) | |
{ | |
while (dr.Read()) | |
{ | |
var domainId = dr.GetInt("id"); | |
result.Add(new umbraco.cms.businesslogic.web.Domain(domainId)); | |
} | |
} | |
return result; | |
} |
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 language | |
/// </summary> | |
public class Language | |
{ | |
/// <summary> | |
/// Gets the unique id for the language | |
/// </summary> | |
public int LanguageId { get; set; } | |
/// <summary> | |
/// Gets the culture code of the language: ie. Danish/Denmark da-dk | |
/// </summary> | |
public string CultureCode { get; set; } | |
/// <summary> | |
/// The user friendly name of the language/country | |
/// </summary> | |
public string FriendlyName { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment