-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from duongminh318/featrure/aspnetcore_identity_…
…database create_identity_user_role
- Loading branch information
Showing
18 changed files
with
2,560 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using eShopSolution.Data.Entities; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace eShopSolution.Data.Configurations | ||
{ | ||
public class AppRoleConfiguration : IEntityTypeConfiguration<AppRole> | ||
{ | ||
public void Configure(EntityTypeBuilder<AppRole> builder) | ||
{ | ||
builder.ToTable("AppRoles"); | ||
|
||
builder.Property(x => x.Description).HasMaxLength(200).IsRequired(); | ||
|
||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using eShopSolution.Data.Entities; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace eShopSolution.Data.Configurations | ||
{ | ||
public class AppUserConfiguration : IEntityTypeConfiguration<AppUser> | ||
{ | ||
// cấu hình lại một số thuộc tình của identity | ||
public void Configure(EntityTypeBuilder<AppUser> builder) | ||
{ | ||
builder.ToTable("AppUsers"); | ||
builder.Property(x => x.FirstName).IsRequired().HasMaxLength(200); | ||
builder.Property(x => x.LastName).IsRequired().HasMaxLength(200); | ||
builder.Property(x => x.Dob).IsRequired(); | ||
|
||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.AspNetCore.Identity; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace eShopSolution.Data.Entities | ||
{ | ||
public class AppRole : IdentityRole<Guid> | ||
{ | ||
public string Description { get; set; } | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Microsoft.AspNetCore.Identity; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace eShopSolution.Data.Entities | ||
{ | ||
// tuỳ chỉnh lại những cái bảng identity tạo ra | ||
public class AppUser : IdentityUser<Guid> | ||
{ | ||
public string FirstName { get; set; } | ||
|
||
public string LastName { get; set; } | ||
|
||
public DateTime Dob { get; set; } | ||
|
||
public List<Cart> Carts { get; set; } | ||
|
||
public List<Order> Orders { get; set; } | ||
|
||
public List<Transaction> Transactions { get; set; } | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using eShopSolution.Data.Entities; | ||
using eShopSolution.Data.Enums; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
using System; | ||
using System.Collections.Generic; | ||
|
@@ -83,6 +84,40 @@ public static void Seed(this ModelBuilder modelBuilder) | |
modelBuilder.Entity<ProductInCategory>().HasData( | ||
new ProductInCategory() { ProductId = 1, CategoryId = 1 } | ||
); | ||
|
||
|
||
// any guid | ||
var roleId = new Guid("8D04DCE2-969A-435D-BBA4-DF3F325983DC"); | ||
var adminId = new Guid("69BD714F-9576-45BA-B5B7-F00649BE00DE"); | ||
modelBuilder.Entity<AppRole>().HasData(new AppRole | ||
{ | ||
Id = roleId, | ||
Name = "admin", | ||
NormalizedName = "admin", | ||
Description = "Administrator role" | ||
}); | ||
|
||
var hasher = new PasswordHasher<AppUser>(); | ||
modelBuilder.Entity<AppUser>().HasData(new AppUser | ||
{ | ||
Id = adminId, | ||
UserName = "admin", | ||
NormalizedUserName = "admin", | ||
Email = "[email protected]", | ||
NormalizedEmail = "[email protected]", | ||
EmailConfirmed = true, | ||
PasswordHash = hasher.HashPassword(null, "Abcd1234$"), | ||
SecurityStamp = string.Empty, | ||
FirstName = "Toan", | ||
LastName = "Bach", | ||
Dob = new DateTime(2020, 01, 31) | ||
}); | ||
|
||
modelBuilder.Entity<IdentityUserRole<Guid>>().HasData(new IdentityUserRole<Guid> | ||
{ | ||
RoleId = roleId, | ||
UserId = adminId | ||
}); | ||
} | ||
|
||
|
||
|
Oops, something went wrong.