public static Role GetUserRole(ClaimsPrincipal identity, CMSDBContext db)
 {
     foreach (var claim in identity.Claims)
     {
         if (claim.Type == ClaimTypes.Role)
         {
             return(db.Roles.SingleOrDefault(role => role.Name.Equals(claim.Value)));
         }
     }
     return(null);
 }
Beispiel #2
0
        public static CMSDBContext Create(string connectionString)
        {
            var optionsBuilder = new DbContextOptionsBuilder <CMSDBContext>();

            optionsBuilder.UseMySQL(connectionString);

            //Ensure database creation
            var context = new CMSDBContext(optionsBuilder.Options);

            context.Database.EnsureCreated();

            return(context);
        }