Refactor more mappers
This commit is contained in:
@@ -1,20 +1,27 @@
|
||||
using AutoMapper;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
internal class AuditMapperProfile : Profile
|
||||
internal class AuditMapperProfile : IMapperProfile
|
||||
{
|
||||
public AuditMapperProfile()
|
||||
public void SetMaps(Mapper mapper)
|
||||
{
|
||||
CreateMap<IAuditItem, AuditLog>()
|
||||
.ForMember(log => log.UserAvatars, expression => expression.Ignore())
|
||||
.ForMember(log => log.UserName, expression => expression.Ignore())
|
||||
.ForMember(log => log.NodeId, expression => expression.MapFrom(item => item.Id))
|
||||
.ForMember(log => log.Timestamp, expression => expression.MapFrom(item => item.CreateDate))
|
||||
.ForMember(log => log.LogType, expression => expression.MapFrom(item => item.AuditType));
|
||||
mapper.SetMap<IAuditItem, AuditLog>(source => new AuditLog(), (source, target) => Map(source, target));
|
||||
}
|
||||
|
||||
// Umbraco.Code.MapAll -UserAvatars -UserName
|
||||
private AuditLog Map(IAuditItem source, AuditLog target)
|
||||
{
|
||||
target.UserId = source.UserId;
|
||||
target.NodeId = source.Id;
|
||||
target.Timestamp = source.CreateDate;
|
||||
target.LogType = source.AuditType.ToString();
|
||||
target.EntityType = source.EntityType;
|
||||
target.Comment = source.Comment;
|
||||
target.Parameters = source.Parameters;
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,48 @@
|
||||
using System.Collections.Generic;
|
||||
using AutoMapper;
|
||||
using Umbraco.Core.Manifest;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Models.Sections;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Sections;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
internal class SectionMapperProfile : Profile
|
||||
internal class SectionMapperProfile : IMapperProfile
|
||||
{
|
||||
private readonly ILocalizedTextService _textService;
|
||||
public SectionMapperProfile(ILocalizedTextService textService)
|
||||
{
|
||||
CreateMap<ISection, Section>()
|
||||
.ForMember(dest => dest.RoutePath, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => textService.Localize("sections/" + src.Alias, (IDictionary<string, string>)null)))
|
||||
.ReverseMap(); //backwards too!
|
||||
_textService = textService;
|
||||
}
|
||||
|
||||
public void SetMaps(Mapper mapper)
|
||||
{
|
||||
mapper.SetMap<ISection, Section>(source => new Section(), Map);
|
||||
|
||||
// this is for AutoMapper ReverseMap - but really?
|
||||
mapper.SetMap<Section, ContentSection>();
|
||||
mapper.SetMap<Section, ContentSection>();
|
||||
mapper.SetMap<Section, ManifestSection>(Map);
|
||||
mapper.SetMap<Section, MediaSection>();
|
||||
mapper.SetMap<Section, MembersSection>();
|
||||
mapper.SetMap<Section, PackagesSection>();
|
||||
mapper.SetMap<Section, SettingsSection>();
|
||||
mapper.SetMap<Section, TranslationSection>();
|
||||
mapper.SetMap<Section, UsersSection>();
|
||||
}
|
||||
|
||||
// Umbraco.Code.MapAll -RoutePath
|
||||
private void Map(ISection source, Section target)
|
||||
{
|
||||
target.Alias = source.Alias;
|
||||
target.Name = _textService.Localize("sections/" + source.Alias);
|
||||
}
|
||||
|
||||
// Umbraco.Code.MapAll
|
||||
private void Map(Section source, ManifestSection target)
|
||||
{
|
||||
target.Alias = source.Alias;
|
||||
target.Name = source.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
using AutoMapper;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
internal class TagMapperProfile : Profile
|
||||
internal class TagMapperProfile : IMapperProfile
|
||||
{
|
||||
public TagMapperProfile()
|
||||
public void SetMaps(Mapper mapper)
|
||||
{
|
||||
CreateMap<ITag, TagModel>();
|
||||
mapper.SetMap<ITag, TagModel>(source => new TagModel(), Map);
|
||||
}
|
||||
|
||||
// Umbraco.Code.MapAll
|
||||
private void Map(ITag source, TagModel target)
|
||||
{
|
||||
target.Id = source.Id;
|
||||
target.Text = source.Text;
|
||||
target.Group = source.Group;
|
||||
target.NodeCount = source.NodeCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user