Beispiel #1
0
        private IdentityResource SeedIdentityResource(IDatabaseContext context)
        {
            var existingIdentityResources = context.Set <IdentityResource>().ToList();

            var claims = context.Set <ClaimType>().ToList();

            var userIdentityResource = new IdentityResource(1, "UserIdentityResource", "-");

            userIdentityResource.AddClaims(claims, 1);

            if (!existingIdentityResources.Any(x => x.Name.Equals(userIdentityResource.Name)))
            {
                context.Attach(userIdentityResource).State = EntityState.Added;
                context.SaveChanges();
                return(userIdentityResource);
            }
            else
            {
                return(existingIdentityResources.First(x => x.Name.Equals(userIdentityResource.Name)));
            }
        }