Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. // Relationship between Profiles and AspNetUsers: 0 to 0
  2. builder.Entity<ApplicationUser>()
  3. .HasOne(b => b.Profile)
  4. .WithOne(a => a.ApplicationUser)
  5. .HasForeignKey<ApplicationUser>(b => b.ProfileId);
  6.  
  7. public async Task<IActionResult> Register(RegisterViewModel model, string returnUrl = null)
  8. {
  9.  
  10. ViewData["ReturnUrl"] = returnUrl;
  11. if (ModelState.IsValid)
  12. {
  13.  
  14. var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
  15.  
  16. var result = await _userManager.CreateAsync(user, model.Password);
  17.  
  18. if (result.Succeeded)
  19. {
  20.  
  21. await _signInManager.SignInAsync(user, isPersistent: false);
  22. _logger.LogInformation(3, "User created a new account with password.");
  23. return RedirectToLocal(returnUrl);
  24. }
  25. AddErrors(result);
  26. }
  27.  
  28. // If we got this far, something failed, redisplay form
  29. return View(model);
  30. }
  31.  
  32. namespace Overnight.Models.Security
  33. {
  34. public class ApplicationUser : IdentityUser<Guid>
  35. {
  36. public string PlainPassword { get; set; }
  37.  
  38. public DateTime CreatedAt {get; set;}
  39.  
  40. public Nullable<DateTime> UpdatedAt {get; set;}
  41.  
  42. public Nullable<DateTime> DeletedAt {get; set;}
  43.  
  44. public Int64 ProfileId { get; set; }
  45.  
  46. public Profile Profile { get; set; }
  47. }
  48. }
  49.  
  50. namespace Overnight.Models
  51. {
  52. public enum GenderType : byte {
  53. Unknown = 0,
  54. Male = 1,
  55. Female = 2,
  56. NotApplicable = 9
  57. }
  58. public class Profile : BaseEntity<Int64>
  59. {
  60. public string FirstName { get; set; }
  61. public string LastName { get; set; }
  62. public GenderType Gender { get; set; }
  63. public Nullable<DateTime> DayOfBirth { get; set; }
  64. public Nullable<DateTime> LastActivityDate { get; set; }
  65. //TODO One to One reference for image and adress
  66. public List<ProfileReview> Reviews { get; set; }
  67. public List<Blog> Blogs { get; set; }
  68. public List<Accomodation> Accomodations { get; set; }
  69. public List<Post> Posts { get; set; }
  70. public List<Wishlist> Wishlists { get; set; }
  71. public List<Invoice> Invoices { get; set; }
  72. public List<Discount> Discounts { get; set; }
  73.  
  74. public Security.ApplicationUser ApplicationUser { get; set; }
  75.  
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement