示例#1
0
        /// <summary>
        /// Inserts a new role with the specified name
        /// </summary>
        /// <param name="name">The name of the role to Insert.</param>
        /// <param name="claims">The claims.</param>
        public void Insert(string name, IEnumerable <Claim> claims)
        {
            var newIdentityRole = new Microsoft.AspNetCore.Identity.IdentityRole {
                Name = name, NormalizedName = name
            };

            this.unitOfWork.RoleRepository.Insert(newIdentityRole);

            foreach (var claim in claims)
            {
                this.unitOfWork.RoleClaimsRepository.Insert(new Microsoft.AspNetCore.Identity.IdentityRoleClaim <string> {
                    RoleId = newIdentityRole.Id, ClaimType = claim.Type, ClaimValue = claim.Value
                });
            }

            this.unitOfWork.Commit();
        }
示例#2
0
        public async Task <HttpResponseMessage> NewRole(RoleBindingDto model)
        {
            var my = new Microsoft.AspNetCore.Identity.IdentityRole {
                Name = model.Name, NormalizedName = model.Name.ToUpper()
            };
            HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.Created);
            await Task.Run(() => {
                _ctx.Roles.Add(my);
                _ctx.SaveChanges();

                if (String.IsNullOrEmpty(my.Id))
                {
                    message = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);
                }
            });

            return(message);
        }
示例#3
0
        private static void AddTestData(CrivDbContext context, IConfiguration _config)
        {
            var testuser = _config.GetSection("TestUser");
            var user     = new CrivServer.Data.Models.ApplicationUser {
                Id                 = "1",
                UserName           = testuser.GetValue <string>("UserName"),
                Email              = testuser.GetValue <string>("Email"),
                NormalizedUserName = testuser.GetValue <string>("NormalizedUserName"),
                NormalizedEmail    = testuser.GetValue <string>("NormalizedEmail"),
                PhoneNumber        = testuser.GetValue <string>("PhoneNumber"),
                PasswordHash       = testuser.GetValue <string>("PasswordHash"),
                UserType           = testuser.GetValue <int>("UserType"),
                UserFolder         = Guid.NewGuid().ToString(),
                SecurityStamp      = Guid.NewGuid().ToString()
            };

            context.ApplicationUsers.Add(user);

            var role = new Microsoft.AspNetCore.Identity.IdentityRole()
            {
                Id = "1", Name = "Creator", NormalizedName = "creator", ConcurrencyStamp = Guid.NewGuid().ToString()
            };

            context.Roles.Add(role);

            var userrole = new Microsoft.AspNetCore.Identity.IdentityUserRole <string>()
            {
                RoleId = "1", UserId = "1"
            };

            context.UserRoles.Add(userrole);

            var page = new CrivServer.Data.Models.DbContentModel {
                content_id         = 1,
                site_id            = 1,
                url                = "test",
                tab_title          = "Test page",
                canonical          = "",
                page_title         = "Test page title",
                meta_description   = "A test page description",
                content_h1         = "h1 test 1",
                main_content       = "A main content on a test page",
                additional_content = "Additional test content",
                layout             = "",
                published_date     = new System.DateTime(),
                content_type       = 0,
                status             = 1,
                redirect_url       = "",
                auth_level         = null
            };

            context.ContentModels.Add(page);

            var page2 = new CrivServer.Data.Models.DbContentModel
            {
                content_id         = 2,
                site_id            = 1,
                url                = "test-2",
                tab_title          = "Test page 2",
                canonical          = "",
                page_title         = "Test page2 title",
                meta_description   = "A test page2 description",
                content_h1         = "h1 test 2",
                main_content       = "A main content on a test page2",
                additional_content = "Additional test content",
                layout             = "",
                published_date     = new System.DateTime(),
                content_type       = 0,
                status             = 1,
                redirect_url       = "",
                auth_level         = 0
            };

            context.ContentModels.Add(page2);

            var aboutpage = new CrivServer.Data.Models.DbContentModel
            {
                content_id         = 3,
                site_id            = 1,
                url                = "about",
                tab_title          = "About page",
                canonical          = "",
                page_title         = "About page title",
                meta_description   = "An about page description",
                content_h1         = "h1 about page",
                main_content       = "A main content on the about page",
                additional_content = "Additional about content",
                layout             = "",
                published_date     = new System.DateTime(),
                content_type       = 0,
                status             = 1,
                redirect_url       = "",
                auth_level         = 1
            };

            context.ContentModels.Add(aboutpage);

            var creationpage = new CrivServer.Data.Models.DbContentModel
            {
                content_id         = 4,
                site_id            = 1,
                url                = "creation",
                tab_title          = "creation page",
                canonical          = "",
                page_title         = "creation page title",
                meta_description   = "An creation page description",
                content_h1         = "h1 creation page",
                main_content       = "A main content on the creation page",
                additional_content = "Additional creation content",
                layout             = "",
                published_date     = new System.DateTime(),
                content_type       = 0,
                status             = 1,
                redirect_url       = "",
                auth_level         = 1
            };

            context.ContentModels.Add(creationpage);

            var randompage = new CrivServer.Data.Models.DbContentModel
            {
                content_id         = 5,
                site_id            = 1,
                url                = "random",
                tab_title          = "random page",
                canonical          = "",
                page_title         = "random page title",
                meta_description   = "An random page description",
                content_h1         = "h1 random page",
                main_content       = "A main content on the random page",
                additional_content = "Additional random content",
                layout             = "",
                published_date     = new System.DateTime(),
                content_type       = 0,
                status             = 1,
                redirect_url       = "",
                auth_level         = 1
            };

            context.ContentModels.Add(randompage);
            context.SaveChanges();
        }