Ejemplo n.º 1
0
 public UnitOfWork(PodNomsDbContext context, ILogger <UnitOfWork> logger,
                   HubLifetimeManager <EntityUpdatesHub> hub)
 {
     _logger  = logger;
     _hub     = hub;
     _context = context;
 }
        public static void SeedUsers(
            UserManager <ApplicationUser> userManager,
            PodNomsDbContext context,
            IConfiguration config)
        {
            var item       = config["AdminUserSettings"];
            var nestedItem = config["AdminUserSettings"];
            var user       = _createUserIfNeeded(
                config["AdminUserSettings:TestUser:UserName"],
                config["AdminUserSettings:TestUser:Name"],
                config["AdminUserSettings:TestUser:Email"],
                config["AdminUserSettings:TestUser:Password"],
                new string[] { "catastrophic-api-calls-allowed", "website-admin", "god-mode" },
                userManager);

            var adminUser = _createUserIfNeeded(
                config["AdminUserSettings:AdminUser:UserName"],
                config["AdminUserSettings:AdminUser:Name"],
                config["AdminUserSettings:AdminUser:Email"],
                config["AdminUserSettings:AdminUser:Password"],
                new string[] { "website-admin" },
                userManager
                );

            if (adminUser == null)
            {
                return;
            }

            var sql = @$ "INSERT INTO dbo.IssuedApiKeys
                    (
                        Id,
                        CreateDate,
                        UpdateDate,
                        Name,
                        Prefix,
                        [Key],
                        Scopes,
                        IsValid,
                        Expires,
                        IssuedToId
                    )
                    VALUES
                    (   NEWID(),
                        SYSDATETIME(),
                        SYSDATETIME(),
                        N'{config[" AdminUserSettings : AdminUser : ApiKeyName "]}',