Skip to content

Instantly share code, notes, and snippets.

@marcduiker
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcduiker/99b5c1f8a45f6b1adff5 to your computer and use it in GitHub Desktop.
Save marcduiker/99b5c1f8a45f6b1adff5 to your computer and use it in GitHub Desktop.
using Sitecore.Data;
using Sitecore.Data.Items;
using SitecorePlayground.Common.Interfaces.Providers;
using SitecorePlayground.News.Models;
namespace SitecorePlayground.News.Providers
{
public class AuthorProviderBasedOnRegularItem
{
private readonly IItemProvider itemProvider;
public AuthorProviderBasedOnRegularItem(IItemProvider itemProvider)
{
this.itemProvider = itemProvider;
}
public Author GetAuthor(string authorId)
{
ID parsedAuthorId;
if (!ID.TryParse(authorId, out parsedAuthorId))
{
return null;
}
return this.GetAuthor(parsedAuthorId);
}
public Author GetAuthor(ID authorId)
{
var authorItem = GetAuthorItem(authorId);
if (authorItem == null)
{
return null;
}
return new Author
{
Company = authorItem[Templates.AuthorTemplate.Fields.AuthorCompany],
Name = authorItem[Templates.AuthorTemplate.Fields.AuthorName]
};
}
private Item GetAuthorItem(ID authorItemId)
{
return itemProvider.GetItem(authorItemId);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment