Merge with 6.0.0
This commit is contained in:
@@ -19,25 +19,28 @@ namespace Umbraco.Core.Models
|
||||
private DateTime? _releaseDate;
|
||||
private DateTime? _expireDate;
|
||||
private int _writer;
|
||||
private string _nodeName;
|
||||
private string _nodeName;//NOTE Once localization is introduced this will be the non-localized Node Name.
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for creating a Content object
|
||||
/// </summary>
|
||||
/// <param name="parentId">Id of the Parent content</param>
|
||||
/// <param name="name">Name of the content</param>
|
||||
/// <param name="parent">Parent <see cref="IContent"/> object</param>
|
||||
/// <param name="contentType">ContentType for the current Content object</param>
|
||||
public Content(int parentId, IContentType contentType)
|
||||
: this(parentId, contentType, new PropertyCollection())
|
||||
{
|
||||
}
|
||||
|
||||
public Content(IContent parent, IContentType contentType)
|
||||
: this(parent, contentType, new PropertyCollection())
|
||||
public Content(string name, IContent parent, IContentType contentType)
|
||||
: this(name, parent, contentType, new PropertyCollection())
|
||||
{
|
||||
}
|
||||
|
||||
public Content(IContent parent, IContentType contentType, PropertyCollection properties)
|
||||
: base(parent, contentType, properties)
|
||||
/// <summary>
|
||||
/// Constructor for creating a Content object
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the content</param>
|
||||
/// <param name="parent">Parent <see cref="IContent"/> object</param>
|
||||
/// <param name="contentType">ContentType for the current Content object</param>
|
||||
/// <param name="properties">Collection of properties</param>
|
||||
public Content(string name, IContent parent, IContentType contentType, PropertyCollection properties)
|
||||
: base(name, parent, contentType, properties)
|
||||
{
|
||||
Mandate.ParameterNotNull(contentType, "contentType");
|
||||
|
||||
@@ -47,11 +50,23 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Constructor for creating a Content object
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the content</param>
|
||||
/// <param name="parentId">Id of the Parent content</param>
|
||||
/// <param name="contentType">ContentType for the current Content object</param>
|
||||
public Content(string name, int parentId, IContentType contentType)
|
||||
: this(name, parentId, contentType, new PropertyCollection())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for creating a Content object
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the content</param>
|
||||
/// <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)
|
||||
: base(parentId, contentType, properties)
|
||||
public Content(string name, int parentId, IContentType contentType, PropertyCollection properties)
|
||||
: base(name, parentId, contentType, properties)
|
||||
{
|
||||
Mandate.ParameterNotNull(contentType, "contentType");
|
||||
|
||||
@@ -189,6 +204,12 @@ namespace Umbraco.Core.Models
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Name of the Node (non-localized).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This Property is kept internal until localization is introduced.
|
||||
/// </remarks>
|
||||
internal string NodeName
|
||||
{
|
||||
get { return _nodeName; }
|
||||
@@ -246,20 +267,20 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Changes the Published state of the content object
|
||||
/// </summary>
|
||||
/// <param name="isPublished">Boolean indicating whether content is published (true) or unpublished (false)</param>
|
||||
public void ChangePublishedState(bool isPublished)
|
||||
public void ChangePublishedState(PublishedState state)
|
||||
{
|
||||
Published = isPublished;
|
||||
//NOTE Should this be checked against the Expire/Release dates?
|
||||
//TODO possibly create new (unpublished version)?
|
||||
Published = state == PublishedState.Published;
|
||||
PublishedState = state;
|
||||
}
|
||||
|
||||
internal PublishedState PublishedState { get; set; }
|
||||
|
||||
/// <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>
|
||||
public void ChangeTrashedState(bool isTrashed, int parentId = -1)
|
||||
public override void ChangeTrashedState(bool isTrashed, int parentId = -1)
|
||||
{
|
||||
Trashed = isTrashed;
|
||||
|
||||
@@ -276,7 +297,7 @@ namespace Umbraco.Core.Models
|
||||
//If the content is trashed and is published it should be marked as unpublished
|
||||
if (isTrashed && Published)
|
||||
{
|
||||
ChangePublishedState(false);
|
||||
ChangePublishedState(PublishedState.Unpublished);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Web;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
@@ -16,7 +17,7 @@ namespace Umbraco.Core.Models
|
||||
{
|
||||
protected IContentTypeComposition ContentTypeBase;
|
||||
private Lazy<int> _parentId;
|
||||
private string _name;
|
||||
private string _name;//NOTE Once localization is introduced this will be the localized Name of the Content/Media.
|
||||
private int _sortOrder;
|
||||
private int _level;
|
||||
private string _path;
|
||||
@@ -25,34 +26,50 @@ namespace Umbraco.Core.Models
|
||||
private int _contentTypeId;
|
||||
private PropertyCollection _properties;
|
||||
|
||||
protected ContentBase(int parentId, IContentTypeComposition contentType, PropertyCollection properties)
|
||||
/// <summary>
|
||||
/// Protected constructor for ContentBase (Base for Content and Media)
|
||||
/// </summary>
|
||||
/// <param name="name">Localized Name of the entity</param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <param name="contentType"></param>
|
||||
/// <param name="properties"></param>
|
||||
protected ContentBase(string name, int parentId, IContentTypeComposition contentType, PropertyCollection properties)
|
||||
{
|
||||
Mandate.ParameterCondition(parentId != 0, "parentId");
|
||||
Mandate.ParameterNotNull(contentType, "contentType");
|
||||
Mandate.ParameterNotNull(properties, "properties");
|
||||
|
||||
_parentId = new Lazy<int>(() => parentId);
|
||||
|
||||
_contentTypeId = int.Parse(contentType.Id.ToString(CultureInfo.InvariantCulture));
|
||||
ContentTypeBase = contentType;
|
||||
Version = Guid.NewGuid();
|
||||
|
||||
_parentId = new Lazy<int>(() => parentId);
|
||||
_name = name;
|
||||
_contentTypeId = int.Parse(contentType.Id.ToString(CultureInfo.InvariantCulture));
|
||||
_properties = properties;
|
||||
_properties.EnsurePropertyTypes(PropertyTypes);
|
||||
Version = Guid.NewGuid();
|
||||
}
|
||||
|
||||
protected ContentBase(IContentBase parent, IContentTypeComposition contentType, PropertyCollection properties)
|
||||
/// <summary>
|
||||
/// Protected constructor for ContentBase (Base for Content and Media)
|
||||
/// </summary>
|
||||
/// <param name="name">Localized Name of the entity</param>
|
||||
/// <param name="parent"></param>
|
||||
/// <param name="contentType"></param>
|
||||
/// <param name="properties"></param>
|
||||
protected ContentBase(string name, IContentBase parent, IContentTypeComposition contentType, PropertyCollection properties)
|
||||
{
|
||||
Mandate.ParameterNotNull(parent, "parent");
|
||||
Mandate.ParameterNotNull(contentType, "contentType");
|
||||
Mandate.ParameterNotNull(properties, "properties");
|
||||
|
||||
_parentId = new Lazy<int>(() => parent.Id);
|
||||
ContentTypeBase = contentType;
|
||||
Version = Guid.NewGuid();
|
||||
|
||||
_parentId = new Lazy<int>(() => parent.Id);
|
||||
_name = name;
|
||||
_contentTypeId = int.Parse(contentType.Id.ToString(CultureInfo.InvariantCulture));
|
||||
ContentTypeBase = contentType;
|
||||
_properties = properties;
|
||||
_properties.EnsurePropertyTypes(PropertyTypes);
|
||||
Version = Guid.NewGuid();
|
||||
}
|
||||
|
||||
private static readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<ContentBase, string>(x => x.Name);
|
||||
@@ -256,11 +273,110 @@ namespace Umbraco.Core.Models
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the value of a Property
|
||||
/// Sets the <see cref="System.Object"/> value of a Property
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <param name="value">Value to set for the Property</param>
|
||||
public virtual void SetValue(string propertyTypeAlias, object value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
SetValueOnProperty(propertyTypeAlias, value);
|
||||
return;
|
||||
}
|
||||
|
||||
// .NET magic to call one of the 'SetPropertyValue' handlers with matching signature
|
||||
((dynamic)this).SetPropertyValue(propertyTypeAlias, (dynamic)value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="System.String"/> value of a Property
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <param name="value">Value to set for the Property</param>
|
||||
public virtual void SetPropertyValue(string propertyTypeAlias, string value)
|
||||
{
|
||||
SetValueOnProperty(propertyTypeAlias, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="System.Int32"/> value of a Property
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <param name="value">Value to set for the Property</param>
|
||||
public virtual void SetPropertyValue(string propertyTypeAlias, int value)
|
||||
{
|
||||
SetValueOnProperty(propertyTypeAlias, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="System.Int64"/> value of a Property
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <param name="value">Value to set for the Property</param>
|
||||
public virtual void SetPropertyValue(string propertyTypeAlias, long value)
|
||||
{
|
||||
string val = value.ToString();
|
||||
SetValueOnProperty(propertyTypeAlias, val);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="System.Boolean"/> value of a Property
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <param name="value">Value to set for the Property</param>
|
||||
public virtual void SetPropertyValue(string propertyTypeAlias, bool value)
|
||||
{
|
||||
int val = Convert.ToInt32(value);
|
||||
SetValueOnProperty(propertyTypeAlias, val);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="System.DateTime"/> value of a Property
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <param name="value">Value to set for the Property</param>
|
||||
public virtual void SetPropertyValue(string propertyTypeAlias, DateTime value)
|
||||
{
|
||||
SetValueOnProperty(propertyTypeAlias, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="System.Web.HttpPostedFile"/> value of a Property
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <param name="value">Value to set for the Property</param>
|
||||
public virtual void SetPropertyValue(string propertyTypeAlias, HttpPostedFile value)
|
||||
{
|
||||
ContentExtensions.SetValue(this, propertyTypeAlias, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="System.Web.HttpPostedFileBase"/> value of a Property
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <param name="value">Value to set for the Property</param>
|
||||
public virtual void SetPropertyValue(string propertyTypeAlias, HttpPostedFileBase value)
|
||||
{
|
||||
ContentExtensions.SetValue(this, propertyTypeAlias, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="System.Web.HttpPostedFileWrapper"/> value of a Property
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <param name="value">Value to set for the Property</param>
|
||||
public virtual void SetPropertyValue(string propertyTypeAlias, HttpPostedFileWrapper value)
|
||||
{
|
||||
ContentExtensions.SetValue(this, propertyTypeAlias, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Private method to set the value of a property
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias"></param>
|
||||
/// <param name="value"></param>
|
||||
private void SetValueOnProperty(string propertyTypeAlias, object value)
|
||||
{
|
||||
if (Properties.Contains(propertyTypeAlias))
|
||||
{
|
||||
@@ -284,5 +400,7 @@ namespace Umbraco.Core.Models
|
||||
{
|
||||
return Properties.Any(property => !property.IsValid()) == false;
|
||||
}
|
||||
|
||||
public abstract void ChangeTrashedState(bool isTrashed, int parentId = -1);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
@@ -53,13 +54,14 @@ namespace Umbraco.Core.Models
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// Sets and uploads the file from a HttpPostedFileBase object as the property value
|
||||
/// </summary>
|
||||
/// <param name="media"><see cref="IMedia"/> to add property value to</param>
|
||||
/// <param name="propertyTypeAlias">Alias of the property to save the value on</param>
|
||||
/// <param name="value">The <see cref="HttpPostedFileBase"/> containing the file that will be uploaded</param>
|
||||
public static void SetValue(this IMedia media, string propertyTypeAlias, HttpPostedFileBase value)
|
||||
public static void SetPropertyValue(this IMedia media, string propertyTypeAlias, HttpPostedFileBase value)
|
||||
{
|
||||
var name =
|
||||
IOHelper.SafeFileName(
|
||||
@@ -77,7 +79,7 @@ namespace Umbraco.Core.Models
|
||||
/// <param name="media"><see cref="IMedia"/> to add property value to</param>
|
||||
/// <param name="propertyTypeAlias">Alias of the property to save the value on</param>
|
||||
/// <param name="value">The <see cref="HttpPostedFile"/> containing the file that will be uploaded</param>
|
||||
public static void SetValue(this IMedia media, string propertyTypeAlias, HttpPostedFile value)
|
||||
public static void SetPropertyValue(this IMedia media, string propertyTypeAlias, HttpPostedFile value)
|
||||
{
|
||||
var name =
|
||||
IOHelper.SafeFileName(
|
||||
@@ -95,19 +97,19 @@ namespace Umbraco.Core.Models
|
||||
/// <param name="media"><see cref="IMedia"/> to add property value to</param>
|
||||
/// <param name="propertyTypeAlias">Alias of the property to save the value on</param>
|
||||
/// <param name="value">The <see cref="HttpPostedFileWrapper"/> containing the file that will be uploaded</param>
|
||||
public static void SetValue(this IMedia media, string propertyTypeAlias, HttpPostedFileWrapper value)
|
||||
public static void SetPropertyValue(this IMedia media, string propertyTypeAlias, HttpPostedFileWrapper value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value.FileName) == false)
|
||||
SetFileOnContent(media, propertyTypeAlias, value.FileName, value.InputStream);
|
||||
}
|
||||
|
||||
*/
|
||||
/// <summary>
|
||||
/// Sets and uploads the file from a HttpPostedFileBase object as the property value
|
||||
/// </summary>
|
||||
/// <param name="content"><see cref="IContent"/> to add property value to</param>
|
||||
/// <param name="propertyTypeAlias">Alias of the property to save the value on</param>
|
||||
/// <param name="value">The <see cref="HttpPostedFileBase"/> containing the file that will be uploaded</param>
|
||||
public static void SetValue(this IContent content, string propertyTypeAlias, HttpPostedFileBase value)
|
||||
public static void SetValue(this IContentBase content, string propertyTypeAlias, HttpPostedFileBase value)
|
||||
{
|
||||
var name =
|
||||
IOHelper.SafeFileName(
|
||||
@@ -125,7 +127,7 @@ namespace Umbraco.Core.Models
|
||||
/// <param name="content"><see cref="IContent"/> to add property value to</param>
|
||||
/// <param name="propertyTypeAlias">Alias of the property to save the value on</param>
|
||||
/// <param name="value">The <see cref="HttpPostedFile"/> containing the file that will be uploaded</param>
|
||||
public static void SetValue(this IContent content, string propertyTypeAlias, HttpPostedFile value)
|
||||
public static void SetValue(this IContentBase content, string propertyTypeAlias, HttpPostedFile value)
|
||||
{
|
||||
var name =
|
||||
IOHelper.SafeFileName(
|
||||
@@ -143,7 +145,7 @@ namespace Umbraco.Core.Models
|
||||
/// <param name="content"><see cref="IContent"/> to add property value to</param>
|
||||
/// <param name="propertyTypeAlias">Alias of the property to save the value on</param>
|
||||
/// <param name="value">The <see cref="HttpPostedFileWrapper"/> containing the file that will be uploaded</param>
|
||||
public static void SetValue(this IContent content, string propertyTypeAlias, HttpPostedFileWrapper value)
|
||||
public static void SetValue(this IContentBase content, string propertyTypeAlias, HttpPostedFileWrapper value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value.FileName) == false)
|
||||
SetFileOnContent(content, propertyTypeAlias, value.FileName, value.InputStream);
|
||||
@@ -174,10 +176,10 @@ namespace Umbraco.Core.Models
|
||||
|
||||
//Look up Prevalues for this upload datatype - if it is an upload datatype
|
||||
var uploadFieldId = new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c");
|
||||
if (property.PropertyType.DataTypeControlId == uploadFieldId)
|
||||
if (property.PropertyType.DataTypeId == uploadFieldId)
|
||||
{
|
||||
//Get Prevalues by the DataType's Id: property.PropertyType.DataTypeId
|
||||
var values = ApplicationContext.Current.Services.DataTypeService.GetPreValuesByDataTypeId(property.PropertyType.DataTypeId);
|
||||
var values = ApplicationContext.Current.Services.DataTypeService.GetPreValuesByDataTypeId(property.PropertyType.DataTypeDefinitionId);
|
||||
var thumbnailSizes = values.FirstOrDefault();
|
||||
//Additional thumbnails configured as prevalues on the DataType
|
||||
if (thumbnailSizes != null)
|
||||
@@ -208,8 +210,8 @@ namespace Umbraco.Core.Models
|
||||
//Only add dimensions to web images
|
||||
if (supportsResizing)
|
||||
{
|
||||
SetPropertyValue(content, uploadFieldConfigNode, "widthFieldAlias", GetDimensions(fs, fileName).Item1);
|
||||
SetPropertyValue(content, uploadFieldConfigNode, "heightFieldAlias", GetDimensions(fs, fileName).Item2);
|
||||
SetPropertyValue(content, uploadFieldConfigNode, "widthFieldAlias", GetDimensions(fs, fileName).Item1.ToString(CultureInfo.InvariantCulture));
|
||||
SetPropertyValue(content, uploadFieldConfigNode, "heightFieldAlias", GetDimensions(fs, fileName).Item2.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -217,7 +219,7 @@ namespace Umbraco.Core.Models
|
||||
SetPropertyValue(content, uploadFieldConfigNode, "heightFieldAlias", string.Empty);
|
||||
}
|
||||
|
||||
SetPropertyValue(content, uploadFieldConfigNode, "lengthFieldAlias", fs.GetSize(fileName));
|
||||
SetPropertyValue(content, uploadFieldConfigNode, "lengthFieldAlias", fs.GetSize(fileName).ToString(CultureInfo.InvariantCulture));
|
||||
SetPropertyValue(content, uploadFieldConfigNode, "extensionFieldAlias", extension);
|
||||
}
|
||||
}
|
||||
@@ -226,7 +228,7 @@ namespace Umbraco.Core.Models
|
||||
property.Value = fs.GetUrl(fileName);
|
||||
}
|
||||
|
||||
private static void SetPropertyValue(IContentBase content, XmlNode uploadFieldConfigNode, string propertyAlias, object propertyValue)
|
||||
private static void SetPropertyValue(IContentBase content, XmlNode uploadFieldConfigNode, string propertyAlias, string propertyValue)
|
||||
{
|
||||
XmlNode propertyNode = uploadFieldConfigNode.SelectSingleNode(propertyAlias);
|
||||
if (propertyNode != null && string.IsNullOrEmpty(propertyNode.FirstChild.Value) == false)
|
||||
@@ -403,9 +405,7 @@ namespace Umbraco.Core.Models
|
||||
{
|
||||
|
||||
//nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias);
|
||||
//var nodeName = content.ContentType.Alias.ToUmbracoAlias(StringAliasCaseType.CamelCase, true);
|
||||
var nodeName = content.ContentType.Alias;
|
||||
|
||||
var nodeName = UmbracoSettings.UseLegacyXmlSchema ? "node" : content.ContentType.Alias.ToSafeAliasWithForcingCheck();
|
||||
var x = content.ToXml(nodeName);
|
||||
x.Add(new XAttribute("nodeType", content.ContentType.Id));
|
||||
x.Add(new XAttribute("creatorName", content.GetCreatorProfile().Name));
|
||||
@@ -458,7 +458,8 @@ namespace Umbraco.Core.Models
|
||||
new XAttribute("nodeName", contentBase.Name),
|
||||
new XAttribute("urlName", niceUrl),//Format Url ?
|
||||
new XAttribute("path", contentBase.Path),
|
||||
new XAttribute("isDoc", ""));
|
||||
new XAttribute("isDoc", ""),
|
||||
UmbracoSettings.UseLegacyXmlSchema ? new XAttribute("nodeTypeAlias", content.ContentType.Alias) : null);
|
||||
|
||||
foreach (var property in contentBase.Properties)
|
||||
{
|
||||
|
||||
@@ -72,6 +72,12 @@ namespace Umbraco.Core.Models
|
||||
/// <param name="template">Default <see cref="ITemplate"/></param>
|
||||
public void SetDefaultTemplate(ITemplate template)
|
||||
{
|
||||
if (template == null)
|
||||
{
|
||||
DefaultTemplateId = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
DefaultTemplateId = template.Id;
|
||||
if(_allowedTemplates.Any(x => x != null && x.Id == template.Id) == false)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
@@ -29,6 +30,7 @@ namespace Umbraco.Core.Models
|
||||
private bool _isContainer;
|
||||
private bool _trashed;
|
||||
private PropertyGroupCollection _propertyGroups;
|
||||
private PropertyTypeCollection _propertyTypes;
|
||||
private IEnumerable<ContentTypeSort> _allowedContentTypes;
|
||||
|
||||
protected ContentTypeBase(int parentId)
|
||||
@@ -38,6 +40,7 @@ namespace Umbraco.Core.Models
|
||||
_parentId = new Lazy<int>(() => parentId);
|
||||
_allowedContentTypes = new List<ContentTypeSort>();
|
||||
_propertyGroups = new PropertyGroupCollection();
|
||||
_propertyTypes = new PropertyTypeCollection();
|
||||
}
|
||||
|
||||
protected ContentTypeBase(IContentTypeBase parent)
|
||||
@@ -47,6 +50,7 @@ namespace Umbraco.Core.Models
|
||||
_parentId = new Lazy<int>(() => parent.Id);
|
||||
_allowedContentTypes = new List<ContentTypeSort>();
|
||||
_propertyGroups = new PropertyGroupCollection();
|
||||
_propertyTypes = new PropertyTypeCollection();
|
||||
}
|
||||
|
||||
private static readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, string>(x => x.Name);
|
||||
@@ -64,12 +68,18 @@ namespace Umbraco.Core.Models
|
||||
private static readonly PropertyInfo TrashedSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, bool>(x => x.Trashed);
|
||||
private static readonly PropertyInfo AllowedContentTypesSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, IEnumerable<ContentTypeSort>>(x => x.AllowedContentTypes);
|
||||
private static readonly PropertyInfo PropertyGroupCollectionSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, PropertyGroupCollection>(x => x.PropertyGroups);
|
||||
private static readonly PropertyInfo PropertyTypeCollectionSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, IEnumerable<PropertyType>>(x => x.PropertyTypes);
|
||||
|
||||
protected void PropertyGroupsChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged(PropertyGroupCollectionSelector);
|
||||
}
|
||||
|
||||
protected void PropertyTypesChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged(PropertyTypeCollectionSelector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the Parent entity
|
||||
/// </summary>
|
||||
@@ -144,7 +154,12 @@ namespace Umbraco.Core.Models
|
||||
get { return _alias; }
|
||||
set
|
||||
{
|
||||
_alias = value;
|
||||
//Ensures a valid ContentType alias
|
||||
//Would have liked to use .ToUmbracoAlias() but that would break casing upon saving older/upgraded ContentTypes
|
||||
var result = Regex.Replace(value, @"[^a-zA-Z0-9\s\.-]+", "", RegexOptions.Compiled);
|
||||
result = result.Replace(" ", "");
|
||||
|
||||
_alias = result;
|
||||
OnPropertyChanged(AliasSelector);
|
||||
}
|
||||
}
|
||||
@@ -301,7 +316,16 @@ namespace Umbraco.Core.Models
|
||||
[IgnoreDataMember]
|
||||
public virtual IEnumerable<PropertyType> PropertyTypes
|
||||
{
|
||||
get { return PropertyGroups.SelectMany(x => x.PropertyTypes); }
|
||||
get
|
||||
{
|
||||
var types = _propertyTypes.Union(PropertyGroups.SelectMany(x => x.PropertyTypes));
|
||||
return types;
|
||||
}
|
||||
internal set
|
||||
{
|
||||
_propertyTypes = new PropertyTypeCollection(value);
|
||||
_propertyTypes.CollectionChanged += PropertyTypesChanged;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -69,14 +69,6 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Changes the Published state of the content object
|
||||
/// </summary>
|
||||
/// <param name="isPublished">Boolean indicating whether content is published (true) or unpublished (false)</param>
|
||||
void ChangePublishedState(bool isPublished);
|
||||
|
||||
/// <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>
|
||||
void ChangeTrashedState(bool isTrashed, int parentId = -1);
|
||||
void ChangePublishedState(PublishedState state);
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ namespace Umbraco.Core.Models
|
||||
TPassType GetValue<TPassType>(string propertyTypeAlias);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the value of a Property
|
||||
/// Sets the <see cref="System.Object"/> value of a Property
|
||||
/// </summary>
|
||||
/// <param name="propertyTypeAlias">Alias of the PropertyType</param>
|
||||
/// <param name="value">Value to set for the Property</param>
|
||||
@@ -77,5 +77,12 @@ namespace Umbraco.Core.Models
|
||||
/// </summary>
|
||||
/// <returns>True if content is valid otherwise false</returns>
|
||||
bool IsValid();
|
||||
|
||||
/// <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>
|
||||
void ChangeTrashedState(bool isTrashed, int parentId = -1);
|
||||
}
|
||||
}
|
||||
@@ -15,20 +15,23 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Constructor for creating a Media object
|
||||
/// </summary>
|
||||
/// <param name="parentId"> </param>
|
||||
/// <param name="name">ame of the Media object</param>
|
||||
/// <param name="parent">Parent <see cref="IMedia"/> object</param>
|
||||
/// <param name="contentType">MediaType for the current Media object</param>
|
||||
public Media(int parentId, IMediaType contentType)
|
||||
: this(parentId, contentType, new PropertyCollection())
|
||||
{
|
||||
}
|
||||
|
||||
public Media(IMedia parent, IMediaType contentType)
|
||||
: this(parent, contentType, new PropertyCollection())
|
||||
public Media(string name, IMedia parent, IMediaType contentType)
|
||||
: this(name, parent, contentType, new PropertyCollection())
|
||||
{
|
||||
}
|
||||
|
||||
public Media(IMedia parent, IMediaType contentType, PropertyCollection properties)
|
||||
: base(parent, contentType, properties)
|
||||
/// <summary>
|
||||
/// Constructor for creating a Media object
|
||||
/// </summary>
|
||||
/// <param name="name">ame of the Media object</param>
|
||||
/// <param name="parent">Parent <see cref="IMedia"/> object</param>
|
||||
/// <param name="contentType">MediaType for the current Media object</param>
|
||||
/// <param name="properties">Collection of properties</param>
|
||||
public Media(string name, IMedia parent, IMediaType contentType, PropertyCollection properties)
|
||||
: base(name, parent, contentType, properties)
|
||||
{
|
||||
Mandate.ParameterNotNull(contentType, "contentType");
|
||||
_contentType = contentType;
|
||||
@@ -37,10 +40,23 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Constructor for creating a Media object
|
||||
/// </summary>
|
||||
/// <param name="parentId"> </param>
|
||||
/// <param name="name">ame of the Media object</param>
|
||||
/// <param name="parentId">Id of the Parent IMedia</param>
|
||||
/// <param name="contentType">MediaType for the current Media object</param>
|
||||
public Media(string name, int parentId, IMediaType contentType)
|
||||
: this(name, parentId, contentType, new PropertyCollection())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for creating a Media object
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the Media object</param>
|
||||
/// <param name="parentId">Id of the Parent IMedia</param>
|
||||
/// <param name="contentType">MediaType for the current Media object</param>
|
||||
/// <param name="properties">Collection of properties</param>
|
||||
public Media(int parentId, IMediaType contentType, PropertyCollection properties) : base(parentId, contentType, properties)
|
||||
public Media(string name, int parentId, IMediaType contentType, PropertyCollection properties)
|
||||
: base(name, parentId, contentType, properties)
|
||||
{
|
||||
Mandate.ParameterNotNull(contentType, "contentType");
|
||||
_contentType = contentType;
|
||||
@@ -95,7 +111,7 @@ namespace Umbraco.Core.Models
|
||||
/// </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)
|
||||
public override void ChangeTrashedState(bool isTrashed, int parentId = -1)
|
||||
{
|
||||
Trashed = isTrashed;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
@@ -13,7 +14,7 @@ namespace Umbraco.Core.Models
|
||||
/// <returns>Xml of the property and its value</returns>
|
||||
public static XElement ToXml(this Property property)
|
||||
{
|
||||
string nodeName = property.Alias.ToUmbracoAlias(StringAliasCaseType.CamelCase, true);
|
||||
string nodeName = UmbracoSettings.UseLegacyXmlSchema ? "data" : property.Alias.ToSafeAlias();
|
||||
|
||||
var xd = new XmlDocument();
|
||||
XmlNode xmlNode = xd.CreateNode(XmlNodeType.Element, nodeName, "");
|
||||
|
||||
@@ -17,8 +17,9 @@ namespace Umbraco.Core.Models
|
||||
private string _name;
|
||||
private string _alias;
|
||||
private string _description;
|
||||
private int _dataTypeId;
|
||||
private Guid _dataTypeControlId;
|
||||
private int _dataTypeDefinitionId;
|
||||
private int _propertyGroupId;
|
||||
private Guid _dataTypeId;
|
||||
private DataTypeDatabaseType _dataTypeDatabaseType;
|
||||
private bool _mandatory;
|
||||
private string _helpText;
|
||||
@@ -28,9 +29,9 @@ namespace Umbraco.Core.Models
|
||||
public PropertyType(IDataTypeDefinition dataTypeDefinition)
|
||||
{
|
||||
if(dataTypeDefinition.HasIdentity)
|
||||
DataTypeId = dataTypeDefinition.Id;
|
||||
DataTypeDefinitionId = dataTypeDefinition.Id;
|
||||
|
||||
DataTypeControlId = dataTypeDefinition.ControlId;
|
||||
DataTypeId = dataTypeDefinition.ControlId;
|
||||
DataTypeDatabaseType = dataTypeDefinition.DatabaseType;
|
||||
|
||||
EnsureSerializationService();
|
||||
@@ -38,7 +39,7 @@ namespace Umbraco.Core.Models
|
||||
|
||||
internal PropertyType(Guid dataTypeControlId, DataTypeDatabaseType dataTypeDatabaseType)
|
||||
{
|
||||
DataTypeControlId = dataTypeControlId;
|
||||
DataTypeId = dataTypeControlId;
|
||||
DataTypeDatabaseType = dataTypeDatabaseType;
|
||||
|
||||
EnsureSerializationService();
|
||||
@@ -53,13 +54,14 @@ namespace Umbraco.Core.Models
|
||||
private static readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<PropertyType, string>(x => x.Name);
|
||||
private static readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<PropertyType, string>(x => x.Alias);
|
||||
private static readonly PropertyInfo DescriptionSelector = ExpressionHelper.GetPropertyInfo<PropertyType, string>(x => x.Description);
|
||||
private static readonly PropertyInfo DataTypeIdSelector = ExpressionHelper.GetPropertyInfo<PropertyType, int>(x => x.DataTypeId);
|
||||
private static readonly PropertyInfo DataTypeControlIdSelector = ExpressionHelper.GetPropertyInfo<PropertyType, Guid>(x => x.DataTypeControlId);
|
||||
private static readonly PropertyInfo DataTypeDefinitionIdSelector = ExpressionHelper.GetPropertyInfo<PropertyType, int>(x => x.DataTypeDefinitionId);
|
||||
private static readonly PropertyInfo DataTypeControlIdSelector = ExpressionHelper.GetPropertyInfo<PropertyType, Guid>(x => x.DataTypeId);
|
||||
private static readonly PropertyInfo DataTypeDatabaseTypeSelector = ExpressionHelper.GetPropertyInfo<PropertyType, DataTypeDatabaseType>(x => x.DataTypeDatabaseType);
|
||||
private static readonly PropertyInfo MandatorySelector = ExpressionHelper.GetPropertyInfo<PropertyType, bool>(x => x.Mandatory);
|
||||
private static readonly PropertyInfo HelpTextSelector = ExpressionHelper.GetPropertyInfo<PropertyType, string>(x => x.HelpText);
|
||||
private static readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo<PropertyType, int>(x => x.SortOrder);
|
||||
private static readonly PropertyInfo ValidationRegExpSelector = ExpressionHelper.GetPropertyInfo<PropertyType, string>(x => x.ValidationRegExp);
|
||||
private static readonly PropertyInfo PropertyGroupIdSelector = ExpressionHelper.GetPropertyInfo<PropertyType, int>(x => x.PropertyGroupId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets of Sets the Name of the PropertyType
|
||||
@@ -108,13 +110,13 @@ namespace Umbraco.Core.Models
|
||||
/// </summary>
|
||||
/// <remarks>This is actually the Id of the <see cref="IDataTypeDefinition"/></remarks>
|
||||
[DataMember]
|
||||
public int DataTypeId
|
||||
public int DataTypeDefinitionId
|
||||
{
|
||||
get { return _dataTypeId; }
|
||||
get { return _dataTypeDefinitionId; }
|
||||
set
|
||||
{
|
||||
_dataTypeId = value;
|
||||
OnPropertyChanged(DataTypeIdSelector);
|
||||
_dataTypeDefinitionId = value;
|
||||
OnPropertyChanged(DataTypeDefinitionIdSelector);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,12 +125,12 @@ namespace Umbraco.Core.Models
|
||||
/// </summary>
|
||||
/// <remarks>This is the Id of the actual DataType control</remarks>
|
||||
[DataMember]
|
||||
internal Guid DataTypeControlId
|
||||
public Guid DataTypeId
|
||||
{
|
||||
get { return _dataTypeControlId; }
|
||||
set
|
||||
get { return _dataTypeId; }
|
||||
internal set
|
||||
{
|
||||
_dataTypeControlId = value;
|
||||
_dataTypeId = value;
|
||||
OnPropertyChanged(DataTypeControlIdSelector);
|
||||
}
|
||||
}
|
||||
@@ -147,6 +149,20 @@ namespace Umbraco.Core.Models
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the PropertyGroup's Id for which this PropertyType belongs
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
internal int PropertyGroupId
|
||||
{
|
||||
get { return _propertyGroupId; }
|
||||
set
|
||||
{
|
||||
_propertyGroupId = value;
|
||||
OnPropertyChanged(PropertyGroupIdSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets of Sets the Boolean indicating whether a value for this PropertyType is required
|
||||
/// </summary>
|
||||
@@ -280,7 +296,7 @@ namespace Umbraco.Core.Models
|
||||
return argument == type;
|
||||
}*/
|
||||
|
||||
if (DataTypeControlId != Guid.Empty)
|
||||
if (DataTypeId != Guid.Empty)
|
||||
{
|
||||
//Find DataType by Id
|
||||
//IDataType dataType = DataTypesResolver.Current.GetById(DataTypeControlId);
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace Umbraco.Core.Models
|
||||
internal static IDataType DataType(this PropertyType propertyType, int propertyId)
|
||||
{
|
||||
Mandate.ParameterNotNull(propertyType, "propertyType");
|
||||
var dataType = ApplicationContext.Current.Services.DataTypeService.GetDataTypeById(propertyType.DataTypeControlId);
|
||||
dataType.DataTypeDefinitionId = propertyType.DataTypeId;
|
||||
var dataType = ApplicationContext.Current.Services.DataTypeService.GetDataTypeById(propertyType.DataTypeId);
|
||||
dataType.DataTypeDefinitionId = propertyType.DataTypeDefinitionId;
|
||||
dataType.Data.PropertyId = propertyId;
|
||||
return dataType;
|
||||
}
|
||||
|
||||
9
src/Umbraco.Core/Models/PublishedState.cs
Normal file
9
src/Umbraco.Core/Models/PublishedState.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
public enum PublishedState
|
||||
{
|
||||
Published,
|
||||
Unpublished,
|
||||
Saved
|
||||
}
|
||||
}
|
||||
@@ -43,11 +43,6 @@ namespace Umbraco.Core.Models.Rdbms
|
||||
[Constraint(Default = "0")]
|
||||
public bool AllowAtRoot { get; set; }
|
||||
|
||||
[Column("masterContentType")]
|
||||
[Constraint(Default = "0")]
|
||||
[NullSetting(NullSetting = NullSettings.Null)]
|
||||
public int MasterContentType { get; set; }//TODO Delete once "masterContentType" has been removed from the Core
|
||||
|
||||
[ResultColumn]
|
||||
public NodeDto NodeDto { get; set; }
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Umbraco.Core.Models.Rdbms
|
||||
public int ContentTypeNodeId { get; set; }
|
||||
|
||||
[Column("templateNodeId")]
|
||||
/*[ForeignKey(typeof(TemplateDto))]*/
|
||||
[ForeignKey(typeof(TemplateDto), Column = "nodeId")]
|
||||
public int TemplateNodeId { get; set; }
|
||||
|
||||
[Column("IsDefault")]
|
||||
|
||||
Reference in New Issue
Block a user