Beispiel #1
0
        protected override void Seed(EMarketDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
            var admin = new ApplicationUser
            {
                Password    = "******".GetMD5Hash(),
                Email       = "*****@*****.**",
                FullName    = "Admin User",
                PicturePath = "default.jpg"
            };

            context.Users.AddOrUpdate(x => x.Email, admin);
            context.SaveChanges();
            context.Roles.AddOrUpdate(x => x.Name, new Role {
                Name = "Customer"
            });
            var adminRole = new Role {
                Name = "Admin"
            };

            context.Roles.AddOrUpdate(x => x.Name, adminRole);
            context.SaveChanges();
            context.Database.ExecuteSqlCommand(string.Format("Insert into {0}.{1} (UserId,RoleId) values (@userid,@roleid)", DbConstants.UserRoles.Schema, DbConstants.UserRoles.Name),
                                               new SqlParameter("@userid", admin.Id),
                                               new SqlParameter("@roleid", adminRole.Id));



            context.SaveChanges();
        }