diff --git a/backend/src/mms.Infrastructure/Seeder/DataGenerator.cs b/backend/src/mms.Infrastructure/Seeder/DataGenerator.cs new file mode 100644 index 0000000..8924e8c --- /dev/null +++ b/backend/src/mms.Infrastructure/Seeder/DataGenerator.cs @@ -0,0 +1,36 @@ +using Bogus; +using mms.Domain.Entities; + +namespace mms.Infrastructure.Seeder +{ + public static class DataGenerator + { + public static readonly List MentorsAndManagers = new(); + + public const int NumberOfMentorsAndManagers = 60; + + public static void InitMentorsAndManagersData() + { + var mentorsAndManagersGenerator = GetMentorsAndManagersGenerator(); + var generatedMentorsAndManagers = mentorsAndManagersGenerator.Generate(NumberOfMentorsAndManagers); + MentorsAndManagers.AddRange(generatedMentorsAndManagers); + } + + private static Faker GetMentorsAndManagersGenerator() + { + return new Faker() + .RuleFor(e => e.Id, _ => Guid.NewGuid().ToString()) + .RuleFor(e => e.About, f => f.Lorem.Paragraph(1)) + .RuleFor(e => e.FirstName, f => f.Name.FirstName()) + .RuleFor(e => e.LastName, f => f.Name.LastName()) + .RuleFor(e => e.IsActive, f => true) + .RuleFor(e => e.DateCreated, f => DateTime.Now) + .RuleFor(e => e.Email, (f, e) => f.Internet.Email(e.FirstName, e.LastName)) + .RuleFor(e => e.EmailConfirmed, f => true) + .RuleFor(e => e.UserName, (f, e) => e.FirstName) + .RuleFor(e => e.Country, f => f.Address.Country()) + .RuleFor(e => e.City, f => f.Address.City()) + .RuleFor(e => e.State, (f, e) => e.City); + } + } +} \ No newline at end of file diff --git a/backend/src/mms.Infrastructure/Seeder/Seeder.cs b/backend/src/mms.Infrastructure/Seeder/Seeder.cs index 42bcb39..a5d5b92 100644 --- a/backend/src/mms.Infrastructure/Seeder/Seeder.cs +++ b/backend/src/mms.Infrastructure/Seeder/Seeder.cs @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using mms.Domain.Entities; -using mms.Domain.Enums; using mms.Infrastructure.Context; using mms.Infrastructure.Policy; @@ -39,6 +38,9 @@ private static async Task SeederRun(UserManager userManager, Applicatio List usersNotifications = new(); List userPrivacy = new(); + DataGenerator.InitMentorsAndManagersData(); + + var mentorsAndManagers = DataGenerator.MentorsAndManagers; var user = new AppUser { @@ -129,25 +131,42 @@ private static async Task SeederRun(UserManager userManager, Applicatio AppUserId = user2.Id, }); - for (var index = 0; index < users.Count; index++) + foreach (AppUser appUser in users) { - switch (index) + await userManager.CreateAsync(appUser, Password); + await userManager.AddToRoleAsync(appUser, Policies.Admin); + } + + foreach (AppUser appUser in mentorsAndManagers) + { + usersNotifications.Add(new UserNotification() + { + Id = Guid.NewGuid().ToString(), + AppUserId = appUser.Id, + }); + + userPrivacy.Add(new UserPrivacy() { - case 0: - await userManager.CreateAsync(users[index], Password); - await userManager.AddToRoleAsync(users[index], Policies.Admin); - break; - case 1: - await userManager.CreateAsync(users[index], Password); - await userManager.AddToRoleAsync(users[index], Policies.Mentor); - break; - default: - await userManager.CreateAsync(users[index], Password); - await userManager.AddToRoleAsync(users[index], Policies.Manager); - break; + Id = Guid.NewGuid().ToString(), + AppUserId = appUser.Id, + }); + } + + for (int i = 0; i < mentorsAndManagers.Count; i++) + { + if (i <= 30) { + await userManager.CreateAsync(mentorsAndManagers[i], Password); + await userManager.AddToRoleAsync(mentorsAndManagers[i], Policies.Mentor); + } else if (i > 30 && i <= 50) { + await userManager.CreateAsync(mentorsAndManagers[i], Password); + await userManager.AddToRoleAsync(mentorsAndManagers[i], Policies.Manager); + } else { + await userManager.CreateAsync(mentorsAndManagers[i], Password); + await userManager.AddToRoleAsync(mentorsAndManagers[i], Policies.Admin); } } + await context.UserNotifications.AddRangeAsync(usersNotifications); await context.UserPrivacy.AddRangeAsync(userPrivacy); await context.SaveChangesAsync(); diff --git a/backend/src/mms.Infrastructure/mms.Infrastructure.csproj b/backend/src/mms.Infrastructure/mms.Infrastructure.csproj index c4a81bf..56c472b 100644 --- a/backend/src/mms.Infrastructure/mms.Infrastructure.csproj +++ b/backend/src/mms.Infrastructure/mms.Infrastructure.csproj @@ -7,6 +7,7 @@ +