Files
Umbraco-CMS/src/Umbraco.Core/Models/Media.cs
Stephan ddf38407d8 U4-4847 Refactor ContentService (#1266)
* U4-4748 - refactor Content-, Media- and MemberTypeRepository

* Cleanup Attempt

* Cleanup OperationStatus

* U4-4748 - refactor Content-, Media- and MemberTypeService

* U4-4748 - cleanup locking

* U4-4748 - refactor Content-, Media- and MemberRepository

* U4-4748 - refactor ContentService (in progress)

* U4-4748 - all unit of work must be completed

* U4-4748 - refactor locks, fix tests

* U4-4748 - deal with fixmes

* U4-4748 - lock table migration

* Update UmbracoVersion

* Fix AuthorizeUpgrade

* U4-4748 - cleanup+bugfix lock objects

* U4-4748 - bugfix

* updates a string interpolation
2016-05-18 10:55:19 +02:00

122 lines
4.9 KiB
C#

using System;
using System.Runtime.Serialization;
using Umbraco.Core.Persistence.Mappers;
namespace Umbraco.Core.Models
{
/// <summary>
/// Represents a Media object
/// </summary>
[Serializable]
[DataContract(IsReference = true)]
public class Media : ContentBase, IMedia
{
private IMediaType _contentType;
/// <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>
public Media(string name, IMedia parent, IMediaType contentType)
: this(name, parent, contentType, new PropertyCollection())
{
}
/// <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;
}
/// <summary>
/// Constructor for creating a Media object
/// </summary>
/// <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(string name, int parentId, IMediaType contentType, PropertyCollection properties)
: base(name, parentId, contentType, properties)
{
Mandate.ParameterNotNull(contentType, "contentType");
_contentType = contentType;
}
/// <summary>
/// Gets the ContentType used by this Media object
/// </summary>
[IgnoreDataMember]
public IMediaType ContentType
{
get { return _contentType; }
}
/// <summary>
/// Changes the <see cref="IMediaType"/> for the current Media object
/// </summary>
/// <param name="contentType">New MediaType for this Media</param>
/// <remarks>Leaves PropertyTypes intact after change</remarks>
public void ChangeContentType(IMediaType contentType)
{
ContentTypeId = contentType.Id;
_contentType = contentType;
ContentTypeBase = contentType;
Properties.EnsurePropertyTypes(PropertyTypes);
Properties.CollectionChanged += PropertiesChanged;
}
/// <summary>
/// Changes the <see cref="IMediaType"/> for the current Media object and removes PropertyTypes,
/// which are not part of the new MediaType.
/// </summary>
/// <param name="contentType">New MediaType for this Media</param>
/// <param name="clearProperties">Boolean indicating whether to clear PropertyTypes upon change</param>
public void ChangeContentType(IMediaType contentType, bool clearProperties)
{
if (clearProperties)
{
ContentTypeId = contentType.Id;
_contentType = contentType;
ContentTypeBase = contentType;
Properties.EnsureCleanPropertyTypes(PropertyTypes);
Properties.CollectionChanged += PropertiesChanged;
return;
}
ChangeContentType(contentType);
}
/// <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 = -20)
{
Trashed = isTrashed;
//The Media Recycle Bin Id is -21 so we correct that here
ParentId = parentId == -20 ? -21 : parentId;
}
}
}