Skip to content

Commit

Permalink
seed correction
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrmee committed Jun 18, 2023
1 parent 468e63b commit 4a1c34d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 39 deletions.
35 changes: 1 addition & 34 deletions src/Infrastructure/Seeding/DataSeeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,56 +155,23 @@ public static async Task SeedCategories(IRepository _repository)
new Category { Name = "Romance" },
new Category { Name = "Biography" },
new Category { Name = "History" },
new Category { Name = "Self-help" },
new Category { Name = "Cooking" },
new Category { Name = "Science" },
new Category { Name = "Technology" },
new Category { Name = "Business" },
new Category { Name = "Finance" },
new Category { Name = "Health" },
new Category { Name = "Fitness" },
new Category { Name = "Travel" },
new Category { Name = "Art" },
new Category { Name = "Music" },
new Category { Name = "Sports" },
new Category { Name = "Religion" },
new Category { Name = "Philosophy" },
new Category { Name = "Psychology" },
new Category { Name = "Education" },
new Category { Name = "Children" },
new Category { Name = "Young Adult" },
new Category { Name = "Reference" },
new Category { Name = "Comics" },
new Category { Name = "Graphic Novels" },
new Category { Name = "Poetry" },
new Category { Name = "Drama" },
new Category { Name = "Classics" },
new Category { Name = "Crime" },
new Category { Name = "Horror" },
new Category { Name = "Humor" },
new Category { Name = "Parenting" },
new Category { Name = "Cookbooks" },
new Category { Name = "Self-improvement" },
new Category { Name = "Motivational" },
new Category { Name = "Biographies" },
new Category { Name = "Autobiographies" },
new Category { Name = "Historical Fiction" },
new Category { Name = "Sci-Fi/Fantasy" },
new Category { Name = "Memoirs" },
new Category { Name = "True Crime" },
new Category { Name = "Suspense" },
new Category { Name = "Political" },
new Category { Name = "Environmental" },
new Category { Name = "Nature" },
new Category { Name = "Parenting" },
new Category { Name = "Relationships" },
new Category { Name = "Crafts" },
new Category { Name = "Hobbies" },
new Category { Name = "Gardening" },
new Category { Name = "Design" },
new Category { Name = "Fashion" },
new Category { Name = "Architecture" },
new Category { Name = "Photography" }
new Category { Name = "Classics" }
};

foreach (var category in categories)
Expand Down
40 changes: 37 additions & 3 deletions src/Infrastructure/Seeding/IdentitySeeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace BookStore.Infrastructure.Seeding;

public class IdentitySeeder
{
public static async Task SeedAspNetRoles(RoleManager<IdentityRole> roleManager)
public static async Task SeedRoles(RoleManager<IdentityRole> roleManager)
{
var roles = new List<IdentityRole>
{
Expand All @@ -24,11 +24,11 @@ public static async Task SeedAspNetRoles(RoleManager<IdentityRole> roleManager)
}
}

public static async Task SeedAdminUser(UserManager<User> userManager)
public static async Task SeedUsers(UserManager<User> userManager)
{
var adminUserName = "admin";
var adminEmail = "admin@example.com";
var adminPassword = "Mercyrme1.";
var adminPassword = "Admin1.";

var adminUser = await userManager.FindByEmailAsync(adminEmail);
if (adminUser == null)
Expand All @@ -42,5 +42,39 @@ public static async Task SeedAdminUser(UserManager<User> userManager)
await userManager.CreateAsync(adminUser, adminPassword);
await userManager.AddToRoleAsync(adminUser, UserRole.Admin);
}

var managerUserName = "manager";
var managerEmail = "manager@example.com";
var managerPassword = "Manager1.";

var managerUser = await userManager.FindByEmailAsync(managerEmail);
if (managerUser == null)
{
managerUser = new User
{
UserName = managerUserName,
Email = managerEmail
};

await userManager.CreateAsync(managerUser, managerPassword);
await userManager.AddToRoleAsync(managerUser, UserRole.Manager);
}

var customerUserName = "customer";
var customerEmail = "customer@example.com";
var customerPassword = "Customer1.";

var customerUser = await userManager.FindByEmailAsync(customerEmail);
if (customerUser == null)
{
customerUser = new User
{
UserName = customerUserName,
Email = customerEmail
};

await userManager.CreateAsync(customerUser, customerPassword);
await userManager.AddToRoleAsync(customerUser, UserRole.Customer);
}
}
}
4 changes: 2 additions & 2 deletions src/Presentation/Configurations/ApplicationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ private static void EnsureDataPopulated(WebApplicationBuilder builder)

DataSeeder.SeedBooks(_repository).Wait();
DataSeeder.SeedCategories(_repository).Wait();
IdentitySeeder.SeedAspNetRoles(_roleManager).Wait();
IdentitySeeder.SeedAdminUser(_userManager).Wait();
IdentitySeeder.SeedRoles(_roleManager).Wait();
IdentitySeeder.SeedUsers(_userManager).Wait();
}

private static void ConfigureRedisCache(WebApplicationBuilder builder)
Expand Down

0 comments on commit 4a1c34d

Please sign in to comment.