Advertisement
Guest User

Untitled

a guest
Dec 20th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. MapperConfiguration config = new MapperConfiguration(c =>
  4. {
  5. c.CreateMap<UserViewModel, ApplicationUsers>().ConvertUsing<UserConvertor>();
  6. });
  7. var mapper = config.CreateMapper();
  8. var user = new UserViewModel
  9. {
  10. Email = "2424ddgas@yahoo.com",
  11. MobileNumber = "test",
  12. Password = "test",
  13. ReTypePassword = "test",
  14. Username = "test",
  15. };
  16. mapper.ConfigurationProvider.AssertConfigurationIsValid();
  17. var result= mapper.Map<ApplicationUsers>(user).Dump();
  18. }
  19.  
  20. public class UserConvertor : ITypeConverter<UserViewModel, ApplicationUsers>
  21. {
  22.  
  23. public ApplicationUsers Convert(UserViewModel source, ApplicationUsers destination, ResolutionContext context)
  24. {
  25. if (context==null||source == null) return null;
  26.  
  27. return new ApplicationUsers
  28. {
  29. UserName = source.Username,
  30. Email = source.Email,
  31. PhoneNumber = source.MobileNumber
  32. };
  33. }
  34. }
  35.  
  36. public class UserViewModel
  37. {
  38. public string MobileNumber { get; set; }
  39. public string Email { get; set; }
  40. public string Username { get; set; }
  41. public string Password { get; set; }
  42. public string ReTypePassword { get; set; }
  43. }
  44.  
  45. public class IdentityUser<TKey> where TKey : IEquatable<TKey>
  46. {
  47. public IdentityUser() {
  48. Roles = new List<IdentityUser<TKey>>();
  49. }
  50.  
  51. public IdentityUser(string userName) : this()
  52. {
  53. UserName = userName;
  54. }
  55.  
  56. public virtual TKey Id { get; set; }
  57. public virtual string UserName { get; set; }
  58. public virtual string NormalizedUserName { get; set; }
  59.  
  60. /// <summary>
  61. /// Email
  62. /// </summary>
  63. public virtual string Email { get; set; }
  64.  
  65. public virtual string NormalizedEmail { get; set; }
  66.  
  67. /// <summary>
  68. /// True if the email is confirmed, default is false
  69. /// </summary>
  70. public virtual bool EmailConfirmed { get; set; }
  71.  
  72. /// <summary>
  73. /// The salted/hashed form of the user password
  74. /// </summary>
  75. public virtual string PasswordHash { get; set; }
  76.  
  77. /// <summary>
  78. /// A random value that should change whenever a users credentials change (password changed, login removed)
  79. /// </summary>
  80. public virtual string SecurityStamp { get; set; }
  81.  
  82. /// <summary>
  83. /// A random value that should change whenever a user is persisted to the store
  84. /// </summary>
  85. public virtual string ConcurrencyStamp { get; set; }
  86.  
  87. /// <summary>
  88. /// PhoneNumber for the user
  89. /// </summary>
  90. public virtual string PhoneNumber { get; set; }
  91.  
  92. /// <summary>
  93. /// True if the phone number is confirmed, default is false
  94. /// </summary>
  95. public virtual bool PhoneNumberConfirmed { get; set; }
  96.  
  97. /// <summary>
  98. /// Is two factor enabled for the user
  99. /// </summary>
  100. public virtual bool TwoFactorEnabled { get; set; }
  101.  
  102. /// <summary>
  103. /// DateTime in UTC when lockout ends, any time in the past is considered not locked out.
  104. /// </summary>
  105. public virtual DateTimeOffset? LockoutEnd { get; set; }
  106.  
  107. /// <summary>
  108. /// Is lockout enabled for this user
  109. /// </summary>
  110. public virtual bool LockoutEnabled { get; set; }
  111.  
  112. /// <summary>
  113. /// Used to record failures for the purposes of lockout
  114. /// </summary>
  115. public virtual int AccessFailedCount { get; set; }
  116.  
  117. /// <summary>
  118. /// Navigation property for users in the role
  119. /// </summary>
  120. public virtual ICollection<IdentityUser<TKey>> Roles { get; set; }
  121.  
  122. /// <summary>
  123. /// Returns a friendly name
  124. /// </summary>
  125. /// <returns></returns>
  126. public override string ToString()
  127. {
  128. return UserName;
  129. }
  130. }
  131.  
  132. public class ApplicationUsers : IdentityUser<Guid>
  133. {
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement