aboutsummaryrefslogtreecommitdiff
path: root/ExamTemplate/Web/Startup.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ExamTemplate/Web/Startup.cs')
-rw-r--r--ExamTemplate/Web/Startup.cs28
1 files changed, 21 insertions, 7 deletions
diff --git a/ExamTemplate/Web/Startup.cs b/ExamTemplate/Web/Startup.cs
index c294566..691d60f 100644
--- a/ExamTemplate/Web/Startup.cs
+++ b/ExamTemplate/Web/Startup.cs
@@ -103,17 +103,31 @@ namespace ExamTemplate.Web
dbContext.Database.Migrate();
var roleManager = (RoleManager<IdentityRole<Guid>>)serviceScope.ServiceProvider.GetService(typeof(RoleManager<IdentityRole<Guid>>));
- if (!dbContext.Roles.Any(x => x.Name == RoleConst.User))
+ foreach (string name in RoleConst.GetAllNames())
{
- IdentityRole<Guid> userRole = new() { Name = RoleConst.User };
- roleManager.CreateAsync(userRole).Wait();
+ if (!dbContext.Roles.Any(x => x.Name == name))
+ {
+ IdentityRole<Guid> role = new IdentityRole<Guid>() { Name = name };
+ roleManager.CreateAsync(role).Wait();
+ }
}
- if (!dbContext.Roles.Any(x => x.Name == RoleConst.Admin))
+
+ /* If you want to create some custom database values at startup
+ * uncomment the following code
+ * and replace OBJCONST_ with your static class with constants (e.g. RoleConst)
+ * replace OBJS_ with the name of the DbSet of your database model (e.g. Roles)
+ * replace OBJ_ with the name of your database model (e.g. Role)
+
+ foreach (string name in OBJCONST_.GetAllNames())
{
- IdentityRole<Guid> adminRole = new() { Name = RoleConst.Admin };
- roleManager.CreateAsync(adminRole).Wait();
+ if (!dbContext.OBJS_.Any(x => x.Name == name))
+ {
+ var entity = new OBJ_() { Id = Guid.NewGuid(), Name = name };
+ dbContext.OBJS_.Add(entity);
+ dbContext.SaveChanges();
+ }
}
-
+ */
}
}
}