Adds Content, ContentStatus and ContentType implementations U4-922 and U4-923.
Hiding language property untill its fully implemented. Making set on Parent Id private. Resolves a naming conflict in DocumentExtensions and DefaultPublishedMediaStore.
This commit is contained in:
531
src/Umbraco.Core/Models/Content.cs
Normal file
531
src/Umbraco.Core/Models/Content.cs
Normal file
@@ -0,0 +1,531 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a Content object
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
public class Content : Entity, IContent
|
||||
{
|
||||
private IContentType _contentType;
|
||||
private int _parentId;
|
||||
private string _name;
|
||||
private int _sortOrder;
|
||||
private int _level;
|
||||
private string _path;
|
||||
private string _template;
|
||||
private int _userId;
|
||||
private bool _trashed;
|
||||
private bool _published;
|
||||
private string _language;
|
||||
private int _contentTypeId;
|
||||
private PropertyCollection _properties;
|
||||
private DateTime? _releaseDate;
|
||||
private DateTime? _expireDate;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for creating a Content object
|
||||
/// </summary>
|
||||
/// <param name="parentId">Id of the Parent content</param>
|
||||
/// <param name="contentType">ContentType for the current Content object</param>
|
||||
public Content(int parentId, IContentType contentType) : this(parentId, contentType, new PropertyCollection())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for creating a Content object
|
||||
/// </summary>
|
||||
/// <param name="parentId">Id of the Parent content</param>
|
||||
/// <param name="contentType">ContentType for the current Content object</param>
|
||||
/// <param name="properties">Collection of properties</param>
|
||||
public Content(int parentId, IContentType contentType, PropertyCollection properties)
|
||||
{
|
||||
_parentId = parentId;
|
||||
_contentTypeId = int.Parse(contentType.Id.ToString(CultureInfo.InvariantCulture));
|
||||
_contentType = contentType;
|
||||
_properties = properties;
|
||||
_properties.EnsurePropertyTypes(PropertyTypes);
|
||||
Version = Guid.NewGuid();
|
||||
}
|
||||
|
||||
private static readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<Content, string>(x => x.Name);
|
||||
private static readonly PropertyInfo ParentIdSelector = ExpressionHelper.GetPropertyInfo<Content, int>(x => x.ParentId);
|
||||
private static readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo<Content, int>(x => x.SortOrder);
|
||||
private static readonly PropertyInfo LevelSelector = ExpressionHelper.GetPropertyInfo<Content, int>(x => x.Level);
|
||||
private static readonly PropertyInfo PathSelector = ExpressionHelper.GetPropertyInfo<Content, string>(x => x.Path);
|
||||
private static readonly PropertyInfo TemplateSelector = ExpressionHelper.GetPropertyInfo<Content, string>(x => x.Template);
|
||||
private static readonly PropertyInfo UserIdSelector = ExpressionHelper.GetPropertyInfo<Content, int>(x => x.UserId);
|
||||
private static readonly PropertyInfo TrashedSelector = ExpressionHelper.GetPropertyInfo<Content, bool>(x => x.Trashed);
|
||||
private static readonly PropertyInfo PublishedSelector = ExpressionHelper.GetPropertyInfo<Content, bool>(x => x.Published);
|
||||
private static readonly PropertyInfo LanguageSelector = ExpressionHelper.GetPropertyInfo<Content, string>(x => x.Language);
|
||||
private static readonly PropertyInfo DefaultContentTypeIdSelector = ExpressionHelper.GetPropertyInfo<Content, int>(x => x.ContentTypeId);
|
||||
private static readonly PropertyInfo ReleaseDateSelector = ExpressionHelper.GetPropertyInfo<Content, DateTime?>(x => x.ReleaseDate);
|
||||
private static readonly PropertyInfo ExpireDateSelector = ExpressionHelper.GetPropertyInfo<Content, DateTime?>(x => x.ExpireDate);
|
||||
private readonly static PropertyInfo PropertyCollectionSelector = ExpressionHelper.GetPropertyInfo<Content, PropertyCollection>(x => x.Properties);
|
||||
void PropertiesChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged(PropertyCollectionSelector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the Parent entity
|
||||
/// </summary>
|
||||
/// <remarks>Might not be necessary if handled as a relation?</remarks>
|
||||
[DataMember]
|
||||
public int ParentId
|
||||
{
|
||||
get { return _parentId; }
|
||||
private set
|
||||
{
|
||||
_parentId = value;
|
||||
OnPropertyChanged(ParentIdSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the current entity
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set {
|
||||
_name = value;
|
||||
OnPropertyChanged(NameSelector);
|
||||
}
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public string UrlName { get { return Name.ToLower().Replace(" ", "-"); } } //TODO Needs to implement proper url casing/syntax
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the sort order of the content entity
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int SortOrder
|
||||
{
|
||||
get { return _sortOrder; }
|
||||
set
|
||||
{
|
||||
_sortOrder = value;
|
||||
OnPropertyChanged(SortOrderSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the level of the content entity
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int Level
|
||||
{
|
||||
get { return _level; }
|
||||
set
|
||||
{
|
||||
_level = value;
|
||||
OnPropertyChanged(LevelSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Path //Setting this value should be handled by the class not the user
|
||||
{
|
||||
get { return _path; }
|
||||
set
|
||||
{
|
||||
_path = value;
|
||||
OnPropertyChanged(PathSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Path to the template used by this Content
|
||||
/// This is used to override the default one from the ContentType
|
||||
/// </summary>
|
||||
/// <remarks>If no template is explicitly set on the Content object, the Default template from the ContentType will be returned</remarks>
|
||||
[DataMember]
|
||||
public virtual string Template
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_template) || _template == null)
|
||||
return _contentType.DefaultTemplate;
|
||||
|
||||
return _template;
|
||||
}
|
||||
set
|
||||
{
|
||||
_template = value;
|
||||
OnPropertyChanged(TemplateSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Id of the user who created this Content
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int UserId
|
||||
{
|
||||
get { return _userId; }
|
||||
set
|
||||
{
|
||||
_userId = value;
|
||||
OnPropertyChanged(UserIdSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current status of the Content
|
||||
/// </summary>
|
||||
public ContentStatus Status
|
||||
{
|
||||
get
|
||||
{
|
||||
if(Trashed)
|
||||
return ContentStatus.Trashed;
|
||||
|
||||
if(ExpireDate.HasValue && DateTime.UtcNow > ExpireDate.Value)
|
||||
return ContentStatus.Expired;
|
||||
|
||||
if(ReleaseDate.HasValue && ReleaseDate.Value > DateTime.UtcNow)
|
||||
return ContentStatus.AwaitingRelease;
|
||||
|
||||
if(Published)
|
||||
return ContentStatus.Published;
|
||||
|
||||
return ContentStatus.Unpublished;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Boolean indicating whether this Content is Trashed or not.
|
||||
/// If Content is Trashed it will be located in the Recyclebin.
|
||||
/// </summary>
|
||||
/// <remarks>When content is trashed it should be unpublished</remarks>
|
||||
[DataMember]
|
||||
public bool Trashed //Setting this value should be handled by the class not the user
|
||||
{
|
||||
get { return _trashed; }
|
||||
internal set
|
||||
{
|
||||
_trashed = value;
|
||||
OnPropertyChanged(TrashedSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Boolean indicating whether this Content is Published or not
|
||||
/// </summary>
|
||||
/// <remarks>Setting Published to true/false should be private or internal</remarks>
|
||||
[DataMember]
|
||||
public bool Published
|
||||
{
|
||||
get { return _published; }
|
||||
internal set
|
||||
{
|
||||
_published = value;
|
||||
OnPropertyChanged(PublishedSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Language of the data contained within this Content object
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
internal string Language
|
||||
{
|
||||
get { return _language; }
|
||||
set
|
||||
{
|
||||
_language = value;
|
||||
OnPropertyChanged(LanguageSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Guid Id of the curent Version
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public Guid Version { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Integer Id of the default ContentType
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int ContentTypeId
|
||||
{
|
||||
get { return _contentTypeId; }
|
||||
protected set
|
||||
{
|
||||
_contentTypeId = value;
|
||||
OnPropertyChanged(DefaultContentTypeIdSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Collection of properties, which make up all the data available for this Content object
|
||||
/// </summary>
|
||||
/// <remarks>Properties are loaded as part of the Content object graph</remarks>
|
||||
[DataMember]
|
||||
public PropertyCollection Properties
|
||||
{
|
||||
get { return _properties; }
|
||||
set
|
||||
{
|
||||
_properties = value;
|
||||
_properties.CollectionChanged += PropertiesChanged;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set property values by alias with an annonymous object
|
||||
/// </summary>
|
||||
[IgnoreDataMember]
|
||||
public object PropertyValues
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
throw new Exception("No properties has been passed in");
|
||||
|
||||
var propertyInfos = value.GetType().GetProperties();
|
||||
foreach (var propertyInfo in propertyInfos)
|
||||
{
|
||||
//Check if a PropertyType with alias exists thus being a valid property
|
||||
var propertyType = PropertyTypes.FirstOrDefault(x => x.Alias == propertyInfo.Name);
|
||||
if (propertyType == null)
|
||||
throw new Exception(
|
||||
string.Format(
|
||||
"The property alias {0} is not valid, because no PropertyType with this alias exists",
|
||||
propertyInfo.Name));
|
||||
|
||||
//Check if a Property with the alias already exists in the collection thus being updated or inserted
|
||||
var item = Properties.FirstOrDefault(x => x.Alias == propertyInfo.Name);
|
||||
if (item != null)
|
||||
{
|
||||
item.Value = propertyInfo.GetValue(value, null);
|
||||
//Update item with newly added value
|
||||
Properties.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Create new Property to add to collection
|
||||
var property = propertyType.CreatePropertyFromValue(propertyInfo.GetValue(value, null));
|
||||
Properties.Add(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of PropertyGroups available on this Content object
|
||||
/// </summary>
|
||||
[IgnoreDataMember]
|
||||
public IEnumerable<PropertyGroup> PropertyGroups { get { return _contentType.CompositionPropertyGroups; } }
|
||||
|
||||
/// <summary>
|
||||
/// List of PropertyTypes available on this Content object
|
||||
/// </summary>
|
||||
[IgnoreDataMember]
|
||||
public IEnumerable<PropertyType> PropertyTypes { get { return _contentType.CompositionPropertyTypes; } }
|
||||
|
||||
/// <summary>
|
||||
/// The date this Content should be released and thus be published
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public DateTime? ReleaseDate
|
||||
{
|
||||
get { return _releaseDate; }
|
||||
set
|
||||
{
|
||||
if(value.HasValue && value.Value > DateTime.UtcNow && Published)
|
||||
ChangePublishedState(false);
|
||||
|
||||
if (value.HasValue && value.Value < DateTime.UtcNow && !Published)
|
||||
ChangePublishedState(true);
|
||||
|
||||
_releaseDate = value;
|
||||
OnPropertyChanged(ReleaseDateSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The date this Content should expire and thus be unpublished
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public DateTime? ExpireDate
|
||||
{
|
||||
get { return _expireDate; }
|
||||
set
|
||||
{
|
||||
if(value.HasValue && DateTime.UtcNow > value.Value && Published)
|
||||
ChangePublishedState(false);
|
||||
|
||||
_expireDate = value;
|
||||
OnPropertyChanged(ExpireDateSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ContentType used by this content object
|
||||
/// </summary>
|
||||
[IgnoreDataMember]
|
||||
public IContentType ContentType
|
||||
{
|
||||
get { return _contentType; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the <see cref="ContentType"/> for the current content object
|
||||
/// </summary>
|
||||
/// <param name="contentType">New ContentType for this content</param>
|
||||
/// <remarks>Leaves PropertyTypes intact after change</remarks>
|
||||
public void ChangeContentType(IContentType contentType)
|
||||
{
|
||||
ContentTypeId = contentType.Id;
|
||||
_contentType = contentType;
|
||||
_properties.EnsurePropertyTypes(PropertyTypes);
|
||||
_properties.CollectionChanged += PropertiesChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the <see cref="ContentType"/> for the current content object and removes PropertyTypes,
|
||||
/// which are not part of the new ContentType.
|
||||
/// </summary>
|
||||
/// <param name="contentType">New ContentType for this content</param>
|
||||
/// <param name="clearProperties">Boolean indicating whether to clear PropertyTypes upon change</param>
|
||||
public void ChangeContentType(IContentType contentType, bool clearProperties)
|
||||
{
|
||||
if(clearProperties)
|
||||
{
|
||||
ContentTypeId = contentType.Id;
|
||||
_contentType = contentType;
|
||||
_properties.EnsureCleanPropertyTypes(PropertyTypes);
|
||||
_properties.CollectionChanged += PropertiesChanged;
|
||||
return;
|
||||
}
|
||||
|
||||
ChangeContentType(contentType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the content object has a property with the supplied alias
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <returns>True if Property with given alias exists, otherwise False</returns>
|
||||
public bool HasProperty(string propertyTypeAlias)
|
||||
{
|
||||
return Properties.Contains(propertyTypeAlias);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of a Property
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <returns><see cref="Property"/> Value as an <see cref="object"/></returns>
|
||||
public object GetValue(string propertyTypeAlias)
|
||||
{
|
||||
return Properties[propertyTypeAlias].Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of a Property
|
||||
/// </summary>
|
||||
/// <typeparam name="TPassType">Type of the value to return</typeparam>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <returns><see cref="Property"/> Value as a <see cref="TPassType"/></returns>
|
||||
public TPassType GetValue<TPassType>(string propertyTypeAlias)
|
||||
{
|
||||
return (TPassType)Properties[propertyTypeAlias].Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the value of a Property
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <param name="value">Value to set for the Property</param>
|
||||
public void SetValue(string propertyTypeAlias, object value)
|
||||
{
|
||||
if (Properties.Contains(propertyTypeAlias))
|
||||
{
|
||||
Properties[propertyTypeAlias].Value = value;
|
||||
return;
|
||||
}
|
||||
|
||||
var propertyType = PropertyTypes.FirstOrDefault(x => x.Alias == propertyTypeAlias);
|
||||
if(propertyType == null)
|
||||
{
|
||||
throw new Exception(string.Format("No PropertyType exists with the supplied alias: {0}", propertyTypeAlias));
|
||||
}
|
||||
Properties.Add(propertyType.CreatePropertyFromValue(value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method to call when Entity is being saved
|
||||
/// </summary>
|
||||
/// <remarks>Created date is set and a Unique key is assigned</remarks>
|
||||
internal override void AddingEntity()
|
||||
{
|
||||
base.AddingEntity();
|
||||
Key = Guid.NewGuid();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method to call when Entity is being updated
|
||||
/// </summary>
|
||||
/// <remarks>Modified Date is set and a new Version guid is set</remarks>
|
||||
internal override void UpdatingEntity()
|
||||
{
|
||||
base.UpdatingEntity();
|
||||
Version = Guid.NewGuid();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the Published state of the content object
|
||||
/// </summary>
|
||||
/// <param name="isPublished">Boolean indicating whether content is published (true) or unpublished (false)</param>
|
||||
internal void ChangePublishedState(bool isPublished)
|
||||
{
|
||||
Published = isPublished;
|
||||
//NOTE Should this be checked against the Expire/Release dates?
|
||||
//TODO possibly create new (unpublished version)?
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the Trashed state of the content object
|
||||
/// </summary>
|
||||
/// <param name="isTrashed">Boolean indicating whether content is trashed (true) or not trashed (false)</param>
|
||||
/// <param name="parentId"> </param>
|
||||
internal void ChangeTrashedState(bool isTrashed, int parentId = -1)
|
||||
{
|
||||
Trashed = isTrashed;
|
||||
|
||||
//If Content is trashed the parent id should be set to that of the RecycleBin
|
||||
if(isTrashed)
|
||||
{
|
||||
ParentId = -20;
|
||||
}
|
||||
else//otherwise set the parent id to the optional parameter, -1 being the fallback
|
||||
{
|
||||
ParentId = parentId;
|
||||
}
|
||||
|
||||
//If the content is trashed and is published it should be marked as unpublished
|
||||
if (isTrashed && Published)
|
||||
{
|
||||
ChangePublishedState(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/Umbraco.Core/Models/ContentStatus.cs
Normal file
10
src/Umbraco.Core/Models/ContentStatus.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum for the various statuses a Content object can have
|
||||
/// </summary>
|
||||
public enum ContentStatus
|
||||
{
|
||||
Unpublished, Published, Expired, Trashed, AwaitingRelease
|
||||
}
|
||||
}
|
||||
406
src/Umbraco.Core/Models/ContentType.cs
Normal file
406
src/Umbraco.Core/Models/ContentType.cs
Normal file
@@ -0,0 +1,406 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the type of a <see cref="Content"/> object
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
public class ContentType : Entity, IContentType
|
||||
{
|
||||
private int _parentId;
|
||||
private string _name;
|
||||
private int _level;
|
||||
private string _path;
|
||||
private string _alias;
|
||||
private string _description;
|
||||
private int _sortOrder;
|
||||
private string _icon;
|
||||
private string _thumbnail;
|
||||
private string _defaultTemplate;
|
||||
private int _userId;
|
||||
private bool _trashed;
|
||||
private PropertyGroupCollection _propertyGroups;
|
||||
private List<IContentTypeComposition> _contentTypeComposition;
|
||||
private IEnumerable<string> _allowedTemplates;
|
||||
private IEnumerable<int> _allowedContentTypes;
|
||||
|
||||
public ContentType()
|
||||
{
|
||||
_allowedTemplates = new List<string>();
|
||||
_allowedContentTypes = new List<int>();
|
||||
_propertyGroups = new PropertyGroupCollection();
|
||||
_contentTypeComposition = new List<IContentTypeComposition>();
|
||||
}
|
||||
|
||||
private static readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<ContentType, string>(x => x.Name);
|
||||
private static readonly PropertyInfo ParentIdSelector = ExpressionHelper.GetPropertyInfo<ContentType, int>(x => x.ParentId);
|
||||
private static readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo<ContentType, int>(x => x.SortOrder);
|
||||
private static readonly PropertyInfo LevelSelector = ExpressionHelper.GetPropertyInfo<ContentType, int>(x => x.Level);
|
||||
private static readonly PropertyInfo PathSelector = ExpressionHelper.GetPropertyInfo<ContentType, string>(x => x.Path);
|
||||
private static readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<ContentType, string>(x => x.Alias);
|
||||
private static readonly PropertyInfo DescriptionSelector = ExpressionHelper.GetPropertyInfo<ContentType, string>(x => x.Description);
|
||||
private static readonly PropertyInfo IconSelector = ExpressionHelper.GetPropertyInfo<ContentType, string>(x => x.Icon);
|
||||
private static readonly PropertyInfo ThumbnailSelector = ExpressionHelper.GetPropertyInfo<ContentType, string>(x => x.Thumbnail);
|
||||
private static readonly PropertyInfo DefaultTemplateSelector = ExpressionHelper.GetPropertyInfo<ContentType, string>(x => x.DefaultTemplate);
|
||||
private static readonly PropertyInfo UserIdSelector = ExpressionHelper.GetPropertyInfo<ContentType, int>(x => x.UserId);
|
||||
private static readonly PropertyInfo TrashedSelector = ExpressionHelper.GetPropertyInfo<ContentType, bool>(x => x.Trashed);
|
||||
private static readonly PropertyInfo AllowedTemplatesSelector = ExpressionHelper.GetPropertyInfo<ContentType, IEnumerable<string>>(x => x.AllowedTemplates);
|
||||
private static readonly PropertyInfo AllowedContentTypesSelector = ExpressionHelper.GetPropertyInfo<ContentType, IEnumerable<int>>(x => x.AllowedContentTypes);
|
||||
private static readonly PropertyInfo ContentTypeCompositionSelector = ExpressionHelper.GetPropertyInfo<ContentType, List<IContentTypeComposition>>(x => x.ContentTypeComposition);
|
||||
private readonly static PropertyInfo PropertyGroupCollectionSelector = ExpressionHelper.GetPropertyInfo<ContentType, PropertyGroupCollection>(x => x.PropertyGroups);
|
||||
void PropertyGroupsChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged(PropertyGroupCollectionSelector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the Parent entity
|
||||
/// </summary>
|
||||
/// <remarks>Might not be necessary if handled as a relation?</remarks>
|
||||
[DataMember]
|
||||
public int ParentId
|
||||
{
|
||||
get { return _parentId; }
|
||||
set
|
||||
{
|
||||
_parentId = value;
|
||||
OnPropertyChanged(ParentIdSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the current entity
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set
|
||||
{
|
||||
_name = value;
|
||||
OnPropertyChanged(NameSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the level of the content entity
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int Level //NOTE Is this relevant for a ContentType?
|
||||
{
|
||||
get { return _level; }
|
||||
set
|
||||
{
|
||||
_level = value;
|
||||
OnPropertyChanged(LevelSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets of sets the path
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Path //NOTE Is this relevant for a ContentType?
|
||||
{
|
||||
get { return _path; }
|
||||
set
|
||||
{
|
||||
_path = value;
|
||||
OnPropertyChanged(PathSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Alias of the ContentType
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Alias
|
||||
{
|
||||
get { return _alias; }
|
||||
set
|
||||
{
|
||||
_alias = value;
|
||||
OnPropertyChanged(AliasSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Description for the ContentType
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Description
|
||||
{
|
||||
get { return _description; }
|
||||
set
|
||||
{
|
||||
_description = value;
|
||||
OnPropertyChanged(DescriptionSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the sort order of the content entity
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int SortOrder
|
||||
{
|
||||
get { return _sortOrder; }
|
||||
set
|
||||
{
|
||||
_sortOrder = value;
|
||||
OnPropertyChanged(SortOrderSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Name of the icon (sprite class) used to identify the ContentType
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Icon
|
||||
{
|
||||
get { return _icon; }
|
||||
set
|
||||
{
|
||||
_icon = value;
|
||||
OnPropertyChanged(IconSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Name of the thumbnail used to identify the ContentType
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Thumbnail
|
||||
{
|
||||
get { return _thumbnail; }
|
||||
set
|
||||
{
|
||||
_thumbnail = value;
|
||||
OnPropertyChanged(ThumbnailSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Path to default Template
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string DefaultTemplate
|
||||
{
|
||||
get { return _defaultTemplate; }
|
||||
set
|
||||
{
|
||||
_defaultTemplate = value;
|
||||
OnPropertyChanged(DefaultTemplateSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Id of the user who created this Content
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int UserId
|
||||
{
|
||||
get { return _userId; }
|
||||
set
|
||||
{
|
||||
_userId = value;
|
||||
OnPropertyChanged(UserIdSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Boolean indicating whether this ContentType is Trashed or not.
|
||||
/// If ContentType is Trashed it will be located in the Recyclebin.
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public bool Trashed //NOTE Is this relevant for a ContentType?
|
||||
{
|
||||
get { return _trashed; }
|
||||
set
|
||||
{
|
||||
_trashed = value;
|
||||
OnPropertyChanged(TrashedSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a list of aliases for allowed Templates
|
||||
/// </summary>
|
||||
public IEnumerable<string> AllowedTemplates
|
||||
{
|
||||
get { return _allowedTemplates; }
|
||||
set
|
||||
{
|
||||
_allowedTemplates = value;
|
||||
OnPropertyChanged(AllowedTemplatesSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a list of integer Ids for allowed ContentTypes
|
||||
/// </summary>
|
||||
public IEnumerable<int> AllowedContentTypes
|
||||
{
|
||||
get { return _allowedContentTypes; }
|
||||
set
|
||||
{
|
||||
_allowedContentTypes = value;
|
||||
OnPropertyChanged(AllowedContentTypesSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of PropertyGroups available on this ContentType
|
||||
/// </summary>
|
||||
/// <remarks>A PropertyGroup corresponds to a Tab in the UI</remarks>
|
||||
[DataMember]
|
||||
public PropertyGroupCollection PropertyGroups
|
||||
{
|
||||
get { return _propertyGroups; }
|
||||
set
|
||||
{
|
||||
_propertyGroups = value;
|
||||
_propertyGroups.CollectionChanged += PropertyGroupsChanged;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of PropertyTypes available on this ContentType.
|
||||
/// This list aggregates PropertyTypes across the PropertyGroups.
|
||||
/// </summary>
|
||||
[IgnoreDataMember]
|
||||
public IEnumerable<PropertyType> PropertyTypes
|
||||
{
|
||||
get { return PropertyGroups.SelectMany(x => x.PropertyTypes); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of ContentTypes that make up a composition of PropertyGroups and PropertyTypes for the current ContentType
|
||||
/// </summary>
|
||||
public List<IContentTypeComposition> ContentTypeComposition
|
||||
{
|
||||
get { return _contentTypeComposition; }
|
||||
set
|
||||
{
|
||||
_contentTypeComposition = value;
|
||||
OnPropertyChanged(ContentTypeCompositionSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of <see cref="PropertyGroup"/> objects from the composition
|
||||
/// </summary>
|
||||
[IgnoreDataMember]
|
||||
public IEnumerable<PropertyGroup> CompositionPropertyGroups
|
||||
{
|
||||
get
|
||||
{
|
||||
var groups = PropertyGroups.Union(ContentTypeComposition.SelectMany(x => x.CompositionPropertyGroups));
|
||||
return groups;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of <see cref="PropertyType"/> objects from the composition
|
||||
/// </summary>
|
||||
[IgnoreDataMember]
|
||||
public IEnumerable<PropertyType> CompositionPropertyTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
var propertyTypes = PropertyTypes.Union(ContentTypeComposition.SelectMany(x => x.CompositionPropertyTypes));
|
||||
return propertyTypes;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new ContentType to the list of composite ContentTypes
|
||||
/// </summary>
|
||||
/// <param name="contentType"><see cref="ContentType"/> to add</param>
|
||||
/// <returns>True if ContentType was added, otherwise returns False</returns>
|
||||
public bool AddContentType(IContentTypeComposition contentType)
|
||||
{
|
||||
if(contentType.ContentTypeComposition.Any(x => x.CompositionAliases().Any(ContentTypeCompositionExists)))
|
||||
return false;
|
||||
|
||||
if (!ContentTypeCompositionExists(contentType.Alias))
|
||||
{
|
||||
ContentTypeComposition.Add(contentType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a ContentType with the supplied alias from the the list of composite ContentTypes
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias of a <see cref="ContentType"/></param>
|
||||
/// <returns>True if ContentType was removed, otherwise returns False</returns>
|
||||
public bool RemoveContentType(string alias)
|
||||
{
|
||||
if (!ContentTypeCompositionExists(alias))
|
||||
{
|
||||
var contentTypeComposition = ContentTypeComposition.First(x => x.Alias == alias);
|
||||
return ContentTypeComposition.Remove(contentTypeComposition);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a ContentType with the supplied alias exists in the list of composite ContentTypes
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias of a <see cref="ContentType"/></param>
|
||||
/// <returns>True if ContentType with alias exists, otherwise returns False</returns>
|
||||
public bool ContentTypeCompositionExists(string alias)
|
||||
{
|
||||
if (ContentTypeComposition.Any(x => x.Alias.Equals(alias)))
|
||||
return true;
|
||||
|
||||
if (ContentTypeComposition.Any(x => x.ContentTypeCompositionExists(alias)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of ContentType aliases from the current composition
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <remarks>Does not contain the alias of the Current ContentType</remarks>
|
||||
public IEnumerable<string> CompositionAliases()
|
||||
{
|
||||
return ContentTypeComposition.Select(x => x.Alias).Union(ContentTypeComposition.SelectMany(x => x.CompositionAliases()));
|
||||
}
|
||||
|
||||
//TODO Implement moving PropertyType between groups.
|
||||
/*public bool MovePropertyTypeToGroup(string propertyTypeAlias, string groupName)
|
||||
{}*/
|
||||
|
||||
/// <summary>
|
||||
/// Method to call when Entity is being saved
|
||||
/// </summary>
|
||||
/// <remarks>Created date is set and a Unique key is assigned</remarks>
|
||||
internal override void AddingEntity()
|
||||
{
|
||||
base.AddingEntity();
|
||||
Key = Guid.NewGuid();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method to call when Entity is being updated
|
||||
/// </summary>
|
||||
/// <remarks>Modified Date is set and a new Version guid is set</remarks>
|
||||
internal override void UpdatingEntity()
|
||||
{
|
||||
base.UpdatingEntity();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Language of the data contained within the Content object
|
||||
/// </summary>
|
||||
string Language { get; set; }
|
||||
//string Language { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Guid Id of the Content's Version
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Gets or Sets the Id of the Parent for the Content
|
||||
/// </summary>
|
||||
int ParentId { get; set; }
|
||||
int ParentId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the Name of the Content
|
||||
|
||||
@@ -92,6 +92,9 @@
|
||||
<Compile Include="IO\IMediaFileSystem.cs" />
|
||||
<Compile Include="Macros\MacroTagParser.cs" />
|
||||
<Compile Include="Mandate.cs" />
|
||||
<Compile Include="Models\Content.cs" />
|
||||
<Compile Include="Models\ContentStatus.cs" />
|
||||
<Compile Include="Models\ContentType.cs" />
|
||||
<Compile Include="Models\DataTypeDatabaseType.cs" />
|
||||
<Compile Include="Models\DataTypeDefinition.cs" />
|
||||
<Compile Include="Models\EntityBase\Entity.cs" />
|
||||
|
||||
@@ -10,6 +10,7 @@ using Umbraco.Core.Dynamics;
|
||||
using Umbraco.Core.Models;
|
||||
using umbraco;
|
||||
using umbraco.cms.businesslogic;
|
||||
using ContentType = umbraco.cms.businesslogic.ContentType;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Routing;
|
||||
using umbraco.cms.businesslogic;
|
||||
using Umbraco.Core;
|
||||
using ContentType = umbraco.cms.businesslogic.ContentType;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user