<commit_before>﻿using System;
using System.Web.Security;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Core.Services.Implement;

namespace Umbraco.Web.Models.Mapping
{
    /// <summary>
    /// Declares model mappings for members.
    /// </summary>
    internal class MemberMapperProfile : Profile
    {
        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<commit_msg>fixes test<commit_after>﻿using System;
using System.Web.Security;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Core.Services.Implement;

namespace Umbraco.Web.Models.Mapping
{
    /// <summary>
    /// Declares model mappings for members.
    /// </summary>
    internal class MemberMapperProfile : Profile
    {
        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())
                .ForMember(dest => dest.VersionId, 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
{'fraction_non_alphanumeric': 0.11029685753322568, 'fraction_numerical': 0.0, 'mean_word_length': 2.58983504235399, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3745167', 'n_tokens_mistral': 2069, 'n_tokens_neox': 1989, 'n_words': 514}