Created
December 20, 2016 15:58
-
-
Save lbargaoanu/d973807dc0ccd8f990675ef0f740a8b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
MapperConfiguration config = new MapperConfiguration(c => | |
{ | |
c.CreateMap<UserViewModel, ApplicationUsers>().ConvertUsing<UserConvertor>(); | |
}); | |
var mapper = config.CreateMapper(); | |
var user = new UserViewModel | |
{ | |
Email = "[email protected]", | |
MobileNumber = "test", | |
Password = "test", | |
ReTypePassword = "test", | |
Username = "test", | |
}; | |
mapper.ConfigurationProvider.AssertConfigurationIsValid(); | |
var result= mapper.Map<ApplicationUsers>(user).Dump(); | |
} | |
public class UserConvertor : ITypeConverter<UserViewModel, ApplicationUsers> | |
{ | |
public ApplicationUsers Convert(UserViewModel source, ApplicationUsers destination, ResolutionContext context) | |
{ | |
if (context==null||source == null) return null; | |
return new ApplicationUsers | |
{ | |
UserName = source.Username, | |
Email = source.Email, | |
PhoneNumber = source.MobileNumber | |
}; | |
} | |
} | |
public class UserViewModel | |
{ | |
public string MobileNumber { get; set; } | |
public string Email { get; set; } | |
public string Username { get; set; } | |
public string Password { get; set; } | |
public string ReTypePassword { get; set; } | |
} | |
public class IdentityUser<TKey> where TKey : IEquatable<TKey> | |
{ | |
public IdentityUser() { | |
Roles = new List<IdentityUser<TKey>>(); | |
} | |
public IdentityUser(string userName) : this() | |
{ | |
UserName = userName; | |
} | |
public virtual TKey Id { get; set; } | |
public virtual string UserName { get; set; } | |
public virtual string NormalizedUserName { get; set; } | |
/// <summary> | |
/// </summary> | |
public virtual string Email { get; set; } | |
public virtual string NormalizedEmail { get; set; } | |
/// <summary> | |
/// True if the email is confirmed, default is false | |
/// </summary> | |
public virtual bool EmailConfirmed { get; set; } | |
/// <summary> | |
/// The salted/hashed form of the user password | |
/// </summary> | |
public virtual string PasswordHash { get; set; } | |
/// <summary> | |
/// A random value that should change whenever a users credentials change (password changed, login removed) | |
/// </summary> | |
public virtual string SecurityStamp { get; set; } | |
/// <summary> | |
/// A random value that should change whenever a user is persisted to the store | |
/// </summary> | |
public virtual string ConcurrencyStamp { get; set; } | |
/// <summary> | |
/// PhoneNumber for the user | |
/// </summary> | |
public virtual string PhoneNumber { get; set; } | |
/// <summary> | |
/// True if the phone number is confirmed, default is false | |
/// </summary> | |
public virtual bool PhoneNumberConfirmed { get; set; } | |
/// <summary> | |
/// Is two factor enabled for the user | |
/// </summary> | |
public virtual bool TwoFactorEnabled { get; set; } | |
/// <summary> | |
/// DateTime in UTC when lockout ends, any time in the past is considered not locked out. | |
/// </summary> | |
public virtual DateTimeOffset? LockoutEnd { get; set; } | |
/// <summary> | |
/// Is lockout enabled for this user | |
/// </summary> | |
public virtual bool LockoutEnabled { get; set; } | |
/// <summary> | |
/// Used to record failures for the purposes of lockout | |
/// </summary> | |
public virtual int AccessFailedCount { get; set; } | |
/// <summary> | |
/// Navigation property for users in the role | |
/// </summary> | |
public virtual ICollection<IdentityUser<TKey>> Roles { get; set; } | |
/// <summary> | |
/// Returns a friendly name | |
/// </summary> | |
/// <returns></returns> | |
public override string ToString() | |
{ | |
return UserName; | |
} | |
} | |
public class ApplicationUsers : IdentityUser<Guid> | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment