2013-06-10 17:01:50 -02:00
|
|
|
|
using System.Text;
|
2013-05-27 01:23:49 -10:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
|
|
|
|
|
using Umbraco.Web.Models.ContentEditing;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Models.Mapping
|
|
|
|
|
|
{
|
2013-06-10 17:01:50 -02:00
|
|
|
|
internal class ContentModelMapper : BaseContentModelMapper
|
2013-05-27 01:23:49 -10:00
|
|
|
|
{
|
2013-06-10 17:01:50 -02:00
|
|
|
|
|
2013-06-17 01:06:31 +02:00
|
|
|
|
public ContentModelMapper(ApplicationContext applicationContext, UserModelMapper userMapper)
|
|
|
|
|
|
: base(applicationContext, userMapper)
|
2013-06-03 23:50:20 -10:00
|
|
|
|
{
|
2013-05-27 01:23:49 -10:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-06-10 20:24:54 -02:00
|
|
|
|
public ContentItemDto<IContent> ToContentItemDto(IContent content)
|
2013-06-10 16:43:42 -02:00
|
|
|
|
{
|
2013-06-10 20:24:54 -02:00
|
|
|
|
var result = base.ToContentItemDtoBase<IContent>(content);
|
2013-06-10 17:01:50 -02:00
|
|
|
|
//NOTE: we don't need this for the dto and it's an extra lookup
|
|
|
|
|
|
//result.ContentTypeAlias = content.ContentType.Alias;
|
|
|
|
|
|
//result.Icon = content.ContentType.Icon;
|
2013-06-17 01:06:31 +02:00
|
|
|
|
//result.Updator = userMapper.ToUserBasic(content.GetWriterProfile());
|
2013-06-10 17:01:50 -02:00
|
|
|
|
return result;
|
2013-06-10 16:43:42 -02:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-06-10 20:24:54 -02:00
|
|
|
|
public ContentItemBasic<ContentPropertyBasic, IContent> ToContentItemSimple(IContent content)
|
2013-06-03 23:50:20 -10:00
|
|
|
|
{
|
2013-06-10 20:24:54 -02:00
|
|
|
|
var result = base.ToContentItemSimpleBase<IContent>(content);
|
2013-06-10 17:01:50 -02:00
|
|
|
|
result.ContentTypeAlias = content.ContentType.Alias;
|
|
|
|
|
|
result.Icon = content.ContentType.Icon;
|
2013-06-17 01:06:31 +02:00
|
|
|
|
result.Updator = UserMapper.ToUserBasic(content.GetWriterProfile());
|
2013-06-03 23:50:20 -10:00
|
|
|
|
return result;
|
2013-06-10 17:01:50 -02:00
|
|
|
|
}
|
2013-06-10 16:43:42 -02:00
|
|
|
|
|
|
|
|
|
|
public ContentItemDisplay ToContentItemDisplay(IContent content)
|
|
|
|
|
|
{
|
|
|
|
|
|
//create the list of tabs for properties assigned to tabs.
|
|
|
|
|
|
var tabs = GetTabs(content);
|
|
|
|
|
|
|
2013-06-10 20:24:54 -02:00
|
|
|
|
var result = CreateContent<ContentItemDisplay, ContentPropertyDisplay, IContent>(content, (display, originalContent) =>
|
2013-06-10 16:43:42 -02:00
|
|
|
|
{
|
|
|
|
|
|
//fill in the rest
|
2013-06-17 01:06:31 +02:00
|
|
|
|
display.Updator = UserMapper.ToUserBasic(content.GetWriterProfile());
|
2013-06-10 16:43:42 -02:00
|
|
|
|
display.ContentTypeAlias = content.ContentType.Alias;
|
|
|
|
|
|
display.Icon = content.ContentType.Icon;
|
|
|
|
|
|
|
|
|
|
|
|
//set display props after the normal properties are alraedy mapped
|
|
|
|
|
|
display.Name = originalContent.Name;
|
|
|
|
|
|
display.Tabs = tabs;
|
|
|
|
|
|
//look up the published version of this item if it is not published
|
|
|
|
|
|
if (content.Published)
|
|
|
|
|
|
{
|
|
|
|
|
|
display.PublishDate = content.UpdateDate;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (content.HasPublishedVersion())
|
|
|
|
|
|
{
|
|
|
|
|
|
var published = ApplicationContext.Services.ContentService.GetPublishedVersion(content.Id);
|
|
|
|
|
|
display.PublishDate = published.UpdateDate;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
display.PublishDate = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}, null, false);
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2013-05-27 01:23:49 -10:00
|
|
|
|
}
|