Skip to content

Instantly share code, notes, and snippets.

@islaytitans

islaytitans/SitecoreItemMapper.cs Secret

Last active Aug 29, 2015
Embed
What would you like to do?
Hackathon - SitecoreItemMapper to Entity
namespace DevToolKit.EntityMapping
{
public class SitecoreItemMapper : ISitecoreItemMapper
{
private ISitecoreFieldMapper _sitecoreFieldMapper = new SitecoreFieldMapper();
public ItemModel MapToEntity(Item item, bool includeStandardFields = false)
{
Assert.IsNotNull(item, "item can not be null");
item.Fields.ReadAll();
var entity = new ItemModel
{
Id = item.ID.ToString(),
itemId = item.ID.ToString(),
Name = item.DisplayName,
Fields = item.Fields.Select(_sitecoreFieldMapper.MapToEntity).ToList(),
};
if (!includeStandardFields)
{
entity.Fields.RemoveAll(x => x.StandardField);
}
entity.Fields = entity.Fields.OrderBy(f => f.SectionSortOrder).ThenBy(f => f.SortOrder).ToList();
return entity;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment