From e3b8d1145ff601af24c53dc6c62353ba0dd7d34c Mon Sep 17 00:00:00 2001 From: Niray Mak <323492@student.fontys.nl> Date: Thu, 15 Apr 2021 18:09:31 +0200 Subject: [PATCH] Seed new admin user In an earlier commit the user was not created in the API side which resulted the user to be seeded as a registered user. --- API/Startup.cs | 10 ++++++++++ Data/Helpers/Seed.cs | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/API/Startup.cs b/API/Startup.cs index 5b0ce879..2bc5f0f7 100644 --- a/API/Startup.cs +++ b/API/Startup.cs @@ -523,6 +523,16 @@ private static void UpdateDatabase(IApplicationBuilder app, IWebHostEnvironment // TODO seed embedded projects } + if(context.User.FirstOrDefault(e => e.IdentityId == "74489498") != null) + { + context.User.Remove(context.User.FirstOrDefault(e => e.IdentityId == "74489498")); + context.SaveChanges(); + } + + context.User.Add(Seed.SeedAdminUser2(roles)); + context.SaveChanges(); + + // Seed call to action options List options = Seed.SeedCallToActionOptions(); foreach(CallToActionOption callToActionOption in options) diff --git a/Data/Helpers/Seed.cs b/Data/Helpers/Seed.cs index 75600115..15a9a523 100644 --- a/Data/Helpers/Seed.cs +++ b/Data/Helpers/Seed.cs @@ -540,6 +540,20 @@ public static List SeedDataSources() }; } + public static User SeedAdminUser2(List roles) + { + Role adminRole = roles.Find(i => i.Name == nameof(Defaults.Roles.Administrator)); + + User user = new User + { + Role = adminRole, + IdentityId = "74489498", + Email = "DeXAdmin@email.com", + Name = "DeX Admin", + }; + + return user; + } } }