public MediaMapperProfile(TabsAndPropertiesResolver <IMedia, MediaItemDisplay> tabsAndPropertiesResolver,
                                  ContentTreeNodeUrlResolver <IMedia, MediaTreeController> contentTreeNodeUrlResolver,
                                  MediaAppResolver mediaAppResolver,
                                  IUserService userService,
                                  ILocalizedTextService textService,
                                  IDataTypeService dataTypeService,
                                  IMediaService mediaService,
                                  IMediaTypeService mediaTypeService,
                                  ILogger logger,
                                  IContentTypeBaseServiceProvider contentTypeBaseServiceProvider)
        {
            // create, capture, cache
            var mediaOwnerResolver      = new OwnerResolver <IMedia>(userService);
            var childOfListViewResolver = new MediaChildOfListViewResolver(mediaService, mediaTypeService);
            var mediaTypeBasicResolver  = new ContentTypeBasicResolver <IMedia, MediaItemDisplay>(contentTypeBaseServiceProvider);

            //FROM IMedia TO MediaItemDisplay
            CreateMap <IMedia, MediaItemDisplay>()
            .ForMember(dest => dest.Udi, opt => opt.MapFrom(content => Udi.Create(Constants.UdiEntityType.Media, content.Key)))
            .ForMember(dest => dest.Owner, opt => opt.MapFrom(src => mediaOwnerResolver.Resolve(src)))
            .ForMember(dest => dest.Icon, opt => opt.MapFrom(content => content.ContentType.Icon))
            .ForMember(dest => dest.ContentTypeAlias, opt => opt.MapFrom(content => content.ContentType.Alias))
            .ForMember(dest => dest.IsChildOfListView, opt => opt.MapFrom(childOfListViewResolver))
            .ForMember(dest => dest.Trashed, opt => opt.MapFrom(content => content.Trashed))
            .ForMember(dest => dest.ContentTypeName, opt => opt.MapFrom(content => content.ContentType.Name))
            .ForMember(dest => dest.Properties, opt => opt.Ignore())
            .ForMember(dest => dest.TreeNodeUrl, opt => opt.MapFrom(contentTreeNodeUrlResolver))
            .ForMember(dest => dest.Notifications, opt => opt.Ignore())
            .ForMember(dest => dest.Errors, opt => opt.Ignore())
            .ForMember(dest => dest.State, opt => opt.MapFrom <ContentSavedState?>(_ => null))
            .ForMember(dest => dest.Edited, opt => opt.Ignore())
            .ForMember(dest => dest.Updater, opt => opt.Ignore())
            .ForMember(dest => dest.Alias, opt => opt.Ignore())
            .ForMember(dest => dest.IsContainer, opt => opt.Ignore())
            .ForMember(dest => dest.Tabs, opt => opt.MapFrom(tabsAndPropertiesResolver))
            .ForMember(dest => dest.AdditionalData, opt => opt.Ignore())
            .ForMember(dest => dest.ContentType, opt => opt.MapFrom(mediaTypeBasicResolver))
            .ForMember(dest => dest.MediaLink, opt => opt.MapFrom(content => string.Join(",", content.GetUrls(Current.Configs.Settings().Content, logger))))
            .ForMember(dest => dest.ContentApps, opt => opt.MapFrom(mediaAppResolver))
            .ForMember(dest => dest.VariesByCulture, opt => opt.MapFrom(src => src.ContentType.VariesByCulture()));


            //FROM IMedia TO ContentItemBasic<ContentPropertyBasic, IMedia>
            CreateMap <IMedia, ContentItemBasic <ContentPropertyBasic> >()
            .ForMember(dest => dest.Udi, opt => opt.MapFrom(src => Udi.Create(Constants.UdiEntityType.Media, src.Key)))
            .ForMember(dest => dest.Owner, opt => opt.MapFrom(src => mediaOwnerResolver.Resolve(src)))
            .ForMember(dest => dest.Icon, opt => opt.MapFrom(src => src.ContentType.Icon))
            .ForMember(dest => dest.Trashed, opt => opt.MapFrom(src => src.Trashed))
            .ForMember(dest => dest.ContentTypeAlias, opt => opt.MapFrom(src => src.ContentType.Alias))
            .ForMember(dest => dest.State, opt => opt.MapFrom <ContentSavedState?>(_ => null))
            .ForMember(dest => dest.Edited, opt => opt.Ignore())
            .ForMember(dest => dest.Updater, opt => opt.Ignore())
            .ForMember(dest => dest.Alias, opt => opt.Ignore())
            .ForMember(dest => dest.AdditionalData, opt => opt.Ignore())
            .ForMember(dest => dest.VariesByCulture, opt => opt.MapFrom(src => src.ContentType.VariesByCulture()));


            //FROM IMedia TO ContentItemDto<IMedia>
            CreateMap <IMedia, ContentPropertyCollectionDto>();
            //.ForMember(dest => dest.Udi, opt => opt.MapFrom(src => Udi.Create(Constants.UdiEntityType.Media, src.Key)))
            //.ForMember(dest => dest.Owner, opt => opt.MapFrom(src => mediaOwnerResolver.Resolve(src)))
            //.ForMember(dest => dest.Published, opt => opt.Ignore())
            //.ForMember(dest => dest.Edited, opt => opt.Ignore())
            //.ForMember(dest => dest.Updater, opt => opt.Ignore())
            //.ForMember(dest => dest.Icon, opt => opt.Ignore())
            //.ForMember(dest => dest.Alias, opt => opt.Ignore())
            //.ForMember(dest => dest.AdditionalData, opt => opt.Ignore());
        }
Ejemplo n.º 2
0
        public MemberMapperProfile(
            MemberTabsAndPropertiesResolver tabsAndPropertiesResolver,
            MemberTreeNodeUrlResolver memberTreeNodeUrlResolver,
            MemberBasicPropertiesResolver memberBasicPropertiesResolver,
            IUserService userService,
            IMemberTypeService memberTypeService,
            IMemberService memberService)
        {
            // create, capture, cache
            var memberOwnerResolver = new OwnerResolver <IMember>(userService);
            var memberProfiderFieldMappingResolver = new MemberProviderFieldResolver();
            var membershipScenarioMappingResolver  = new MembershipScenarioResolver(memberTypeService);
            var memberDtoPropertiesResolver        = new MemberDtoPropertiesResolver();

            //FROM MembershipUser TO MediaItemDisplay - used when using a non-umbraco membership provider
            CreateMap <MembershipUser, MemberDisplay>().ConvertUsing <MembershipUserTypeConverter>();

            //FROM MembershipUser TO IMember - used when using a non-umbraco membership provider
            CreateMap <MembershipUser, IMember>()
            .ConstructUsing(src => MemberService.CreateGenericMembershipProviderMember(src.UserName, src.Email, src.UserName, ""))
            //we're giving this entity an ID of int.MaxValue - TODO: SD: I can't remember why this mapping is here?
            .ForMember(dest => dest.Id, opt => opt.MapFrom(src => int.MaxValue))
            .ForMember(dest => dest.Comments, opt => opt.MapFrom(src => src.Comment))
            .ForMember(dest => dest.CreateDate, opt => opt.MapFrom(src => src.CreationDate))
            .ForMember(dest => dest.UpdateDate, opt => opt.MapFrom(src => src.LastActivityDate))
            .ForMember(dest => dest.LastPasswordChangeDate, opt => opt.MapFrom(src => src.LastPasswordChangedDate))
            .ForMember(dest => dest.Key, opt => opt.MapFrom(src => src.ProviderUserKey.TryConvertTo <Guid>().Result.ToString("N")))
            //This is a special case for password - we don't actually care what the password is but it either needs to be something or nothing
            // so we'll set it to something if the member is actually created, otherwise nothing if it is a new member.
            .ForMember(dest => dest.RawPasswordValue, opt => opt.MapFrom(src => src.CreationDate > DateTime.MinValue ? Guid.NewGuid().ToString("N") : ""))
            .ForMember(dest => dest.Properties, opt => opt.Ignore())
            .ForMember(dest => dest.CreatorId, opt => opt.Ignore())
            .ForMember(dest => dest.Level, opt => opt.Ignore())
            .ForMember(dest => dest.Name, opt => opt.Ignore())
            .ForMember(dest => dest.CultureInfos, opt => opt.Ignore())
            .ForMember(dest => dest.ParentId, opt => opt.Ignore())
            .ForMember(dest => dest.Path, opt => opt.Ignore())
            .ForMember(dest => dest.SortOrder, opt => opt.Ignore())
            .ForMember(dest => dest.AdditionalData, opt => opt.Ignore())
            .ForMember(dest => dest.FailedPasswordAttempts, opt => opt.Ignore())
            .ForMember(dest => dest.DeleteDate, opt => opt.Ignore())
            .ForMember(dest => dest.WriterId, opt => opt.Ignore())
            //TODO: Support these eventually
            .ForMember(dest => dest.PasswordQuestion, opt => opt.Ignore())
            .ForMember(dest => dest.RawPasswordAnswerValue, opt => opt.Ignore());

            //FROM IMember TO MemberDisplay
            CreateMap <IMember, MemberDisplay>()
            .ForMember(dest => dest.Udi, opt => opt.MapFrom(content => Udi.Create(Constants.UdiEntityType.Member, content.Key)))
            .ForMember(dest => dest.Owner, opt => opt.ResolveUsing(src => memberOwnerResolver.Resolve(src)))
            .ForMember(dest => dest.Icon, opt => opt.MapFrom(src => src.ContentType.Icon))
            .ForMember(dest => dest.ContentTypeAlias, opt => opt.MapFrom(src => src.ContentType.Alias))
            .ForMember(dest => dest.ContentTypeName, opt => opt.MapFrom(src => src.ContentType.Name))
            .ForMember(dest => dest.Properties, opt => opt.Ignore())
            .ForMember(dest => dest.Tabs, opt => opt.ResolveUsing(tabsAndPropertiesResolver))
            .ForMember(dest => dest.MemberProviderFieldMapping, opt => opt.ResolveUsing(src => memberProfiderFieldMappingResolver.Resolve(src)))
            .ForMember(dest => dest.MembershipScenario, opt => opt.ResolveUsing(src => membershipScenarioMappingResolver.Resolve(src)))
            .ForMember(dest => dest.Notifications, opt => opt.Ignore())
            .ForMember(dest => dest.Errors, opt => opt.Ignore())
            .ForMember(dest => dest.State, opt => opt.UseValue <ContentSavedState?>(null))
            .ForMember(dest => dest.Edited, opt => opt.Ignore())
            .ForMember(dest => dest.Updater, opt => opt.Ignore())
            .ForMember(dest => dest.Alias, opt => opt.Ignore())
            .ForMember(dest => dest.IsChildOfListView, opt => opt.Ignore())
            .ForMember(dest => dest.Trashed, opt => opt.Ignore())
            .ForMember(dest => dest.IsContainer, opt => opt.Ignore())
            .ForMember(dest => dest.TreeNodeUrl, opt => opt.ResolveUsing(memberTreeNodeUrlResolver))
            .ForMember(dest => dest.VariesByCulture, opt => opt.Ignore());

            //FROM IMember TO MemberBasic
            CreateMap <IMember, MemberBasic>()
            //we're giving this entity an ID of int.MaxValue - this is kind of a hack to force angular to use the Key instead of the Id in list views
            .ForMember(dest => dest.Id, opt => opt.MapFrom(src => int.MaxValue))
            .ForMember(dest => dest.Udi, opt => opt.MapFrom(content => Udi.Create(Constants.UdiEntityType.Member, content.Key)))
            .ForMember(dest => dest.Owner, opt => opt.ResolveUsing(src => memberOwnerResolver.Resolve(src)))
            .ForMember(dest => dest.Icon, opt => opt.MapFrom(src => src.ContentType.Icon))
            .ForMember(dest => dest.ContentTypeAlias, opt => opt.MapFrom(src => src.ContentType.Alias))
            .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Email))
            .ForMember(dest => dest.Username, opt => opt.MapFrom(src => src.Username))
            .ForMember(dest => dest.Trashed, opt => opt.Ignore())
            .ForMember(dest => dest.State, opt => opt.UseValue <ContentSavedState?>(null))
            .ForMember(dest => dest.Edited, opt => opt.Ignore())
            .ForMember(dest => dest.Updater, opt => opt.Ignore())
            .ForMember(dest => dest.Alias, opt => opt.Ignore())
            .ForMember(dto => dto.Properties, expression => expression.ResolveUsing(memberBasicPropertiesResolver))
            .ForMember(dest => dest.VariesByCulture, opt => opt.Ignore());

            //FROM MembershipUser TO MemberBasic
            CreateMap <MembershipUser, MemberBasic>()
            //we're giving this entity an ID of int.MaxValue - TODO: SD: I can't remember why this mapping is here?
            .ForMember(dest => dest.Id, opt => opt.MapFrom(src => int.MaxValue))
            .ForMember(dest => dest.Udi, opt => opt.Ignore())
            .ForMember(dest => dest.CreateDate, opt => opt.MapFrom(src => src.CreationDate))
            .ForMember(dest => dest.UpdateDate, opt => opt.MapFrom(src => src.LastActivityDate))
            .ForMember(dest => dest.Key, opt => opt.MapFrom(src => src.ProviderUserKey.TryConvertTo <Guid>().Result.ToString("N")))
            .ForMember(dest => dest.Owner, opt => opt.UseValue(new UserProfile {
                Name = "Admin", UserId = -1
            }))
            .ForMember(dest => dest.Icon, opt => opt.UseValue("icon-user"))
            .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.UserName))
            .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Email))
            .ForMember(dest => dest.Username, opt => opt.MapFrom(src => src.UserName))
            .ForMember(dest => dest.Properties, opt => opt.Ignore())
            .ForMember(dest => dest.ParentId, opt => opt.Ignore())
            .ForMember(dest => dest.Path, opt => opt.Ignore())
            .ForMember(dest => dest.SortOrder, opt => opt.Ignore())
            .ForMember(dest => dest.AdditionalData, opt => opt.Ignore())
            .ForMember(dest => dest.State, opt => opt.UseValue(ContentSavedState.Draft))
            .ForMember(dest => dest.Edited, opt => opt.Ignore())
            .ForMember(dest => dest.Updater, opt => opt.Ignore())
            .ForMember(dest => dest.Trashed, opt => opt.Ignore())
            .ForMember(dest => dest.Alias, opt => opt.Ignore())
            .ForMember(dest => dest.ContentTypeAlias, opt => opt.Ignore())
            .ForMember(dest => dest.VariesByCulture, opt => opt.Ignore());

            //FROM IMember TO ContentItemDto<IMember>
            CreateMap <IMember, ContentPropertyCollectionDto>()
            //.ForMember(dest => dest.Udi, opt => opt.MapFrom(content => Udi.Create(Constants.UdiEntityType.Member, content.Key)))
            //.ForMember(dest => dest.Owner, opt => opt.ResolveUsing(src => memberOwnerResolver.Resolve(src)))
            //.ForMember(dest => dest.Published, opt => opt.Ignore())
            //.ForMember(dest => dest.Edited, opt => opt.Ignore())
            //.ForMember(dest => dest.Updater, opt => opt.Ignore())
            //.ForMember(dest => dest.Icon, opt => opt.Ignore())
            //.ForMember(dest => dest.Alias, opt => opt.Ignore())
            //do no map the custom member properties (currently anyways, they were never there in 6.x)
            .ForMember(dest => dest.Properties, opt => opt.ResolveUsing(src => memberDtoPropertiesResolver.Resolve(src)));

            //FROM IMemberGroup TO MemberGroupDisplay
            CreateMap <IMemberGroup, MemberGroupDisplay>()
            .ForMember(dest => dest.Udi, opt => opt.MapFrom(src => Udi.Create(Constants.UdiEntityType.MemberGroup, src.Key)))
            .ForMember(dest => dest.Path, opt => opt.MapFrom(group => "-1," + group.Id))
            .ForMember(dest => dest.Notifications, opt => opt.Ignore())
            .ForMember(dest => dest.Icon, opt => opt.Ignore())
            .ForMember(dest => dest.Trashed, opt => opt.Ignore())
            .ForMember(dest => dest.ParentId, opt => opt.Ignore())
            .ForMember(dest => dest.Alias, opt => opt.Ignore());
        }
        public ContentMapperProfile(
            ContentUrlResolver contentUrlResolver,
            ContentTreeNodeUrlResolver <IContent, ContentTreeController> contentTreeNodeUrlResolver,
            TabsAndPropertiesResolver <IContent, ContentVariantDisplay> tabsAndPropertiesResolver,
            ContentAppResolver contentAppResolver,
            IUserService userService,
            IContentService contentService,
            IContentTypeService contentTypeService,
            IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
            ILocalizationService localizationService,
            ILocalizedTextService localizedTextService)
        {
            // create, capture, cache
            var contentOwnerResolver            = new OwnerResolver <IContent>(userService);
            var creatorResolver                 = new CreatorResolver(userService);
            var actionButtonsResolver           = new ActionButtonsResolver(userService, contentService);
            var childOfListViewResolver         = new ContentChildOfListViewResolver(contentService, contentTypeService);
            var contentTypeBasicResolver        = new ContentTypeBasicResolver <IContent, ContentItemDisplay>(contentTypeBaseServiceProvider);
            var allowedTemplatesResolver        = new AllowedTemplatesResolver(contentTypeService, localizedTextService);
            var defaultTemplateResolver         = new DefaultTemplateResolver();
            var variantResolver                 = new ContentVariantResolver(localizationService);
            var schedPublishReleaseDateResolver = new ScheduledPublishDateResolver(ContentScheduleAction.Release);
            var schedPublishExpireDateResolver  = new ScheduledPublishDateResolver(ContentScheduleAction.Expire);

            //FROM IContent TO ContentItemDisplay
            CreateMap <IContent, ContentItemDisplay>()
            .ForMember(dest => dest.Udi, opt => opt.MapFrom(src => Udi.Create(src.Blueprint ? Constants.UdiEntityType.DocumentBlueprint : Constants.UdiEntityType.Document, src.Key)))
            .ForMember(dest => dest.Owner, opt => opt.MapFrom(src => contentOwnerResolver.Resolve(src)))
            .ForMember(dest => dest.Updater, opt => opt.MapFrom(src => creatorResolver.Resolve(src)))
            .ForMember(dest => dest.Variants, opt => opt.MapFrom(variantResolver))
            .ForMember(dest => dest.ContentApps, opt => opt.MapFrom(contentAppResolver))
            .ForMember(dest => dest.Icon, opt => opt.MapFrom(src => src.ContentType.Icon))
            .ForMember(dest => dest.ContentTypeAlias, opt => opt.MapFrom(src => src.ContentType.Alias))
            .ForMember(dest => dest.ContentTypeName, opt => opt.MapFrom(src => localizedTextService.UmbracoDictionaryTranslate(src.ContentType.Name)))
            .ForMember(dest => dest.IsContainer, opt => opt.MapFrom(src => src.ContentType.IsContainer))
            .ForMember(dest => dest.IsElement, opt => opt.MapFrom(src => src.ContentType.IsElement))
            .ForMember(dest => dest.IsBlueprint, opt => opt.MapFrom(src => src.Blueprint))
            .ForMember(dest => dest.IsChildOfListView, opt => opt.MapFrom(childOfListViewResolver))
            .ForMember(dest => dest.Trashed, opt => opt.MapFrom(src => src.Trashed))
            .ForMember(dest => dest.TemplateAlias, opt => opt.MapFrom(defaultTemplateResolver))
            .ForMember(dest => dest.Urls, opt => opt.MapFrom(contentUrlResolver))
            .ForMember(dest => dest.AllowPreview, opt => opt.Ignore())
            .ForMember(dest => dest.TreeNodeUrl, opt => opt.MapFrom(contentTreeNodeUrlResolver))
            .ForMember(dest => dest.Notifications, opt => opt.Ignore())
            .ForMember(dest => dest.Errors, opt => opt.Ignore())
            .ForMember(dest => dest.DocumentType, opt => opt.MapFrom(contentTypeBasicResolver))
            .ForMember(dest => dest.AllowedTemplates, opt => opt.MapFrom(allowedTemplatesResolver))
            .ForMember(dest => dest.AllowedActions, opt => opt.MapFrom(src => actionButtonsResolver.Resolve(src)))
            .ForMember(dest => dest.AdditionalData, opt => opt.Ignore());

            CreateMap <IContent, ContentVariantDisplay>()
            .ForMember(dest => dest.PublishDate, opt => opt.MapFrom(src => src.PublishDate))
            .ForMember(dest => dest.ReleaseDate, opt => opt.MapFrom(schedPublishReleaseDateResolver))
            .ForMember(dest => dest.ExpireDate, opt => opt.MapFrom(schedPublishExpireDateResolver))
            .ForMember(dest => dest.Segment, opt => opt.Ignore())
            .ForMember(dest => dest.Language, opt => opt.Ignore())
            .ForMember(dest => dest.Notifications, opt => opt.Ignore())
            .ForMember(dest => dest.State, opt => opt.MapFrom <ContentSavedStateResolver <ContentPropertyDisplay> >())
            .ForMember(dest => dest.Tabs, opt => opt.MapFrom(tabsAndPropertiesResolver));

            //FROM IContent TO ContentItemBasic<ContentPropertyBasic, IContent>
            CreateMap <IContent, ContentItemBasic <ContentPropertyBasic> >()
            .ForMember(dest => dest.Udi, opt => opt.MapFrom(src =>
                                                            Udi.Create(src.Blueprint ? Constants.UdiEntityType.DocumentBlueprint : Constants.UdiEntityType.Document, src.Key)))
            .ForMember(dest => dest.Owner, opt => opt.MapFrom(src => contentOwnerResolver.Resolve(src)))
            .ForMember(dest => dest.Updater, opt => opt.MapFrom(src => creatorResolver.Resolve(src)))
            .ForMember(dest => dest.Icon, opt => opt.MapFrom(src => src.ContentType.Icon))
            .ForMember(dest => dest.Trashed, opt => opt.MapFrom(src => src.Trashed))
            .ForMember(dest => dest.ContentTypeAlias, opt => opt.MapFrom(src => src.ContentType.Alias))
            .ForMember(dest => dest.Alias, opt => opt.Ignore())
            .ForMember(dest => dest.AdditionalData, opt => opt.Ignore())
            .ForMember(dest => dest.UpdateDate, opt => opt.MapFrom <UpdateDateResolver>())
            .ForMember(dest => dest.Name, opt => opt.MapFrom <NameResolver>())
            .ForMember(dest => dest.State, opt => opt.MapFrom <ContentBasicSavedStateResolver <ContentPropertyBasic> >())
            .ForMember(dest => dest.VariesByCulture, opt => opt.MapFrom(src => src.ContentType.VariesByCulture()));

            //FROM IContent TO ContentPropertyCollectionDto
            //NOTE: the property mapping for cultures relies on a culture being set in the mapping context
            CreateMap <IContent, ContentPropertyCollectionDto>();
        }