/
ContentDocument.cs
71 lines (62 loc) · 1.72 KB
/
ContentDocument.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
namespace UmbracoDynamicDoc
{
public class ContentDocument
{
public string Name { get; set; }
public int Id { get; set; }
public string ContentType { get; set; }
public int ContentTypeId { get; set; }
public int ParentId { get; set; }
public int Level { get; set; }
public string Path { get; set; }
public ICollection<Property> Properties { get; set; }
public ContentDocument()
{
Properties = new List<Property>();
}
public ContentDocument(IDataTypeService service, IContent content) : this()
{
Id = content.Id;
ContentTypeId = content.ContentTypeId;
ContentType = content.ContentType.Name;
Name = content.Name;
ParentId = content.ParentId;
Level = content.Level;
Path = content.Path;
foreach (var propInfo in content.PropertyTypes.OrderBy(n => n.SortOrder))
{
var p = new Property
{
Name = propInfo.Name,
Alias = propInfo.Alias,
Description = propInfo.Description,
Required = propInfo.Mandatory,
Validation = propInfo.ValidationRegExp,
DataType = service.GetDataTypeDefinitionById(propInfo.DataTypeDefinitionId).Name,
Value = (content.Properties.SingleOrDefault(n => n.Alias == propInfo.Alias).Value ?? string.Empty).ToString()
};
Properties.Add(p);
}
}
public void ToDocument(IContent document)
{
document.Id = Id;
document.Name = Name;
document.ParentId = ParentId;
foreach (var property in Properties)
{
if (document.HasProperty(property.Alias))
{
document.Properties[property.Alias].Value = property.Value;
}
}
}
}
}