Esempio n. 1
0
 /// <summary>
 /// Adds the services to UI mappings.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <returns>
 /// The services to UI mappings.
 /// </returns>
 public static IMappingConfiguration AddServicesToUIMappings(this IMappingConfiguration configuration)
 {
     return(configuration
            .Configure <ExternalLoginInfo, ExternalLoginViewModel>(
                mapping => mapping
                .Map(elvm => elvm.Email, eli => eli.Principal.FindFirstValue(ClaimTypes.Email))
                .Map(
                    elvm => elvm.Name,
                    eli => eli.Principal.HasClaim(claim => claim.Type == ClaimTypes.GivenName) &&
                    eli.Principal.HasClaim(claim => claim.Type == ClaimTypes.Surname)
                         ? $"{eli.Principal.FindFirstValue(ClaimTypes.GivenName)} {eli.Principal.FindFirstValue(ClaimTypes.Surname)}"
                         : eli.Principal.FindFirstValue(ClaimTypes.Name))
                .Map(elvm => elvm.DateOfBirth, eli => DateTime.Parse(eli.Principal.FindFirstValue(ClaimTypes.DateOfBirth)))));
 }
Esempio n. 2
0
 /// <summary>
 /// Adds the automatic mapper data to services mappings.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <returns>
 /// The automatic mapper data to services mappings.
 /// </returns>
 public static IMappingConfiguration AddDataToServicesMappings(this IMappingConfiguration configuration)
 {
     return(configuration
            .Configure <UserLoginInfo, UserLogin>(
                mapping => mapping
                .Ignore(ul => ul.Id)
                .Ignore(ul => ul.UserId)
                .Ignore(ul => ul.RowVersion))
            .Configure <UserLogin, UserLoginInfo>(
                mapping => mapping
                .Construct(ul => new UserLoginInfo(ul.LoginProvider, ul.ProviderKey, ul.ProviderDisplayName)))
            .Configure <Claim, UserClaim>(
                mapping => mapping
                .Ignore(uc => uc.Id)
                .Ignore(uc => uc.RowVersion)
                .Ignore(uc => uc.UserId))
            .Configure <UserClaim, Claim>(
                mapping => mapping
                .Construct(uc => new Claim(uc.Type, uc.Value))
                .Ignore(c => c.Properties)));
 }
Esempio n. 3
0
 /// <summary>
 /// Adds the data to UI mappings.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <returns>
 /// The data to UI mappings.
 /// </returns>
 public static IMappingConfiguration AddDataToUIMappings(this IMappingConfiguration configuration)
 {
     return(configuration
            .Configure <ExternalLoginViewModel, User>(
                mapping => mapping
                .Ignore(u => u.EmailConfirmed)
                .Map(u => u.FullName, elvm => elvm.Name)
                .Ignore(u => u.Id)
                .Ignore(u => u.PasswordHash)
                .Ignore(u => u.PhoneNumber)
                .Ignore(u => u.PhoneNumberConfirmed)
                .Ignore(u => u.RowVersion)
                .Ignore(u => u.TwoFactorEnabled))
            .Configure <RegistrationViewModel, User>(
                mapping => mapping
                .Ignore(u => u.EmailConfirmed)
                .Map(u => u.FullName, rvm => rvm.Name)
                .Ignore(u => u.Id)
                .Ignore(u => u.PasswordHash)
                .Ignore(u => u.PhoneNumber)
                .Ignore(u => u.PhoneNumberConfirmed)
                .Ignore(u => u.RowVersion)
                .Ignore(u => u.TwoFactorEnabled)));
 }
Esempio n. 4
0
 /// <summary>
 /// Applies the specified configuration
 /// </summary>
 /// <typeparam name="TSource">The type to map from</typeparam>
 /// <typeparam name="TDestination">The type to map to</typeparam>
 /// <param name="profile">The <see cref="Profile"/> to configure</param>
 /// <param name="configuration">The <see cref="IMappingConfiguration{TSource, TDestination}"/> to apply</param>
 public static void ApplyConfiguration <TSource, TDestination>(this Profile profile, IMappingConfiguration <TSource, TDestination> configuration)
 {
     configuration.Configure(profile.CreateMap <TSource, TDestination>());
 }