Skip to content

Instantly share code, notes, and snippets.

@florisrobbemont
Created March 13, 2013 20:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save florisrobbemont/5155690 to your computer and use it in GitHub Desktop.
Save florisrobbemont/5155690 to your computer and use it in GitHub Desktop.
Umbraco Get All Domains
/// <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; }
}
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;
}
/// <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