Add sample data toggle to user provisioning
This commit is contained in:
@@ -15,8 +15,9 @@ internal static class UserProvisioning
|
||||
/// </summary>
|
||||
/// <param name="db">The application database context.</param>
|
||||
/// <param name="userId">Optional user id to validate or create.</param>
|
||||
/// <param name="populateSampleData">Whether to populate sample data for new users.</param>
|
||||
/// <returns>The existing or newly created user.</returns>
|
||||
public static async Task<User> EnsureUserAsync(AppDbContext db, string? userId)
|
||||
public static async Task<User> EnsureUserAsync(AppDbContext db, string? userId, bool populateSampleData)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(userId) && IsValidUserId(userId))
|
||||
{
|
||||
@@ -29,7 +30,10 @@ internal static class UserProvisioning
|
||||
var created = new User { Id = userId };
|
||||
db.Users.Add(created);
|
||||
await db.SaveChangesAsync();
|
||||
await PopulateSampleDataAsync(db, created);
|
||||
if (populateSampleData)
|
||||
{
|
||||
await PopulateSampleDataAsync(db, created);
|
||||
}
|
||||
return created;
|
||||
}
|
||||
|
||||
@@ -45,7 +49,10 @@ internal static class UserProvisioning
|
||||
var user = new User { Id = newId };
|
||||
db.Users.Add(user);
|
||||
await db.SaveChangesAsync();
|
||||
await PopulateSampleDataAsync(db, user);
|
||||
if (populateSampleData)
|
||||
{
|
||||
await PopulateSampleDataAsync(db, user);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user