Exemple #1
0
        public bool CreateRole(ApplicationRoleManager roleManager, string name, string description = "")
        {
            var idResult = roleManager.Create(new ApplicationRole(name, description));

            return(idResult.Succeeded);
        }
Exemple #2
0
        public bool Seed(ApplicationDbContext context)
        {
#if DEBUG
            ApplicationRoleManager roleManager = new ApplicationRoleManager(new RoleStore <ApplicationRole>(context));

            var success = CreateRole(roleManager, "Admin", "Global Access");
            if (!success)
            {
                return(false);
            }

            success = CreateRole(roleManager, "User", "Restricted to business domain activity");
            if (!success)
            {
                return(false);
            }

            ApplicationUserManager userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(context));

            //admin
            ApplicationUser adminUser = new ApplicationUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };
            userManager.Create(adminUser, "Demo123!");
            success = AddUserToRole(userManager, adminUser.Id, "Admin");

            //demoUser1
            var user = new ApplicationUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };
            userManager.Create(user, "Demo123!");
            success = success && AddUserToRole(userManager, user.Id, "User");

            //demoUser2
            var user2 = new ApplicationUser
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };
            userManager.Create(user2, "Demo123!");
            success = success && AddUserToRole(userManager, user2.Id, "User");

            //DemoResource1
            var resource = new Resource();
            resource.Name = "DemoResource1";
            context.Resources.Add(resource);

            //DemoResource2
            var resource2 = new Resource();
            resource2.Name = "DemoResource2";
            context.Resources.Add(resource2);

            //DemoReservation
            var reservation = new Reservation()
            {
                Resource = resource,
                Begin    = DateTime.Now,
                End      = DateTime.Now.AddYears(2),
                User     = user
            };
            context.Reservations.Add(reservation);
            context.SaveChanges();

            return(success);
#endif
#pragma warning disable 162
            // ReSharper disable once HeuristicUnreachableCode
            return(true);

#pragma warning restore 162
        }
Exemple #3
0
 public bool RoleExists(ApplicationRoleManager roleManager, string name)
 {
     return(roleManager.RoleExists(name));
 }