Exemplo n.º 1
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.Entity <UserRoles>()
            .HasKey(bc => new { bc.UserId, bc.RoleId });
            builder.Entity <UserRoles>()
            .HasOne(bc => bc.User)
            .WithMany(b => b.UserRoles)
            .HasForeignKey(x => x.UserId);
            builder.Entity <UserRoles>()
            .HasOne(bc => bc.Role)
            .WithMany(bc => bc.UserRoles)
            .HasForeignKey(x => x.RoleId);

            Role adminRole = new Role {
                RoleId = 1, RoleName = "Admin"
            };
            Role userRole = new Role {
                RoleId = 2, RoleName = "User"
            };

            builder.Entity <Role>().HasData(new Role[] { adminRole, userRole });

            User adminUser = new User
            {
                UserId   = 1,
                Email    = "*****@*****.**",
                Password = CreateHash.GetHashString("admin1203"),
                Name     = "Admin",
                SurName  = "Adminovich",
                IsDelete = false
            };
            User odenryUser = new User
            {
                UserId   = 2,
                Email    = "*****@*****.**",
                Password = CreateHash.GetHashString("user123"),
                Name     = "Golden",
                SurName  = "Coffild",
                IsDelete = false
            };

            builder.Entity <User>().HasData(new User[] { adminUser, odenryUser });
            UserRoles userRoles = new UserRoles
            {
                RoleId = adminRole.RoleId,
                UserId = adminUser.UserId
            };
            UserRoles odenryRole = new UserRoles
            {
                RoleId = userRole.RoleId,
                UserId = odenryUser.UserId
            };

            builder.Entity <UserRoles>().HasData(new UserRoles[] { userRoles, odenryRole });

            base.OnModelCreating(builder);
        }
Exemplo n.º 2
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            Users newUser = new Users
            {
                UserId   = 1,
                UserName = "******",
                Password = CreateHash.GetHashString("123456")
            };

            builder.Entity <Users>().HasData(new Users[] { newUser });

            base.OnModelCreating(builder);
        }