Files
Umbraco-CMS/src/Umbraco.Core/Models/DictionaryItem.cs
T
sitereactor a9bc0addfb Implements ILocalizationService for U4-1075
Refactoring DictionaryItem, DictionaryTranslation and Language to use the same interface implementations as the rest of the db driven repos and services.
2012-10-24 12:22:52 -02:00

85 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Serialization;
using Umbraco.Core.Models.EntityBase;
namespace Umbraco.Core.Models
{
/// <summary>
/// Represents a Dictionary Item
/// </summary>
[Serializable]
[DataContract(IsReference = true)]
public class DictionaryItem : Entity, IDictionaryItem
{
private Guid _parentId;
private string _itemKey;
private IEnumerable<IDictionaryTranslation> _translations;
public DictionaryItem(Guid parentId, string itemKey)
{
_parentId = parentId;
_itemKey = itemKey;
_translations = new List<IDictionaryTranslation>();
}
private static readonly PropertyInfo ParentIdSelector = ExpressionHelper.GetPropertyInfo<DictionaryItem, Guid>(x => x.ParentId);
private static readonly PropertyInfo ItemKeySelector = ExpressionHelper.GetPropertyInfo<DictionaryItem, string>(x => x.ItemKey);
private static readonly PropertyInfo TranslationsSelector = ExpressionHelper.GetPropertyInfo<DictionaryItem, IEnumerable<IDictionaryTranslation>>(x => x.Translations);
/// <summary>
/// Gets or Sets the Parent Id of the Dictionary Item
/// </summary>
[DataMember]
public Guid ParentId
{
get { return _parentId; }
set
{
_parentId = value;
OnPropertyChanged(ParentIdSelector);
}
}
/// <summary>
/// Gets or sets the Key for the Dictionary Item
/// </summary>
[DataMember]
public string ItemKey
{
get { return _itemKey; }
set
{
_itemKey = value;
OnPropertyChanged(ItemKeySelector);
}
}
/// <summary>
/// Gets or sets a list of translations for the Dictionary Item
/// </summary>
[DataMember]
public IEnumerable<IDictionaryTranslation> Translations
{
get { return _translations; }
set
{
_translations = value;
OnPropertyChanged(TranslationsSelector);
}
}
/// <summary>
/// Method to call before inserting a new entity in the db
/// </summary>
internal override void AddingEntity()
{
base.AddingEntity();
//If ParentId is not set we should default to the root parent id
if(ParentId == Guid.Empty)
_parentId = new Guid("41c7638d-f529-4bff-853e-59a0c2fb1bde");
}
}
}