static CategoryTreeNode BuildEntry(Category category, IEnumerable<Category> all)
{
var entry = new CategoryTreeNode
{
Id = category.Id,
Name = category.Name,
Description = category.Description,
Photo = category.Photo,
CustomFields = category.CustomFields.ToDictionary(f => f.Name, f => f.Value)
};
foreach (var child in all.Where(c => c.Parent != null && c.Parent.Id == category.Id))
{
var childEntry = BuildEntry(child, all);
entry.Children.Add(childEntry);
childEntry.Parent = entry;
}
return entry;
}