We now seed some fundamental roles on db create

This commit is contained in:
Michael 2017-03-21 11:26:06 -04:00
parent d2cf4c4d45
commit a6e9911eab

View file

@ -9,24 +9,41 @@ internal sealed class Configuration : DbMigrationsConfiguration<Project_Unite.Mo
{ {
public Configuration() public Configuration()
{ {
AutomaticMigrationsEnabled = false; AutomaticMigrationsEnabled = true;
ContextKey = "Project_Unite.Models.ApplicationDbContext"; ContextKey = "Project_Unite.Models.ApplicationDbContext";
} }
protected override void Seed(Project_Unite.Models.ApplicationDbContext context) protected override void Seed(Project_Unite.Models.ApplicationDbContext context)
{ {
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method var adm = new Models.Role
// to avoid creating duplicate seed data. E.g. {
// Id = "administrator",
// context.People.AddOrUpdate( ColorHex = "#FF0000",
// p => p.FullName, Description = "These are the admins of the website - This is a persistent group and cannot be deleted.",
// new Person { FullName = "Andrew Peters" }, Priority = context.Roles.Count() + 1,
// new Person { FullName = "Brice Lambson" }, Name = "Administrators"
// new Person { FullName = "Rowan Miller" } });
// ); foreach (var prop in adm.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
// {
if (prop.Name.StartsWith("Can") && prop.PropertyType == typeof(bool))
{
prop.SetValue(adm, true);
} }
} }
context.Roles.AddOrUpdate(adm);
var userRole = new Models.Role
{
Name = "Users",
Id = "user",
Description = "This is the default role for all new users. This role's priority may not be modified, and this role may not be deleted.",
Priority = 0,
ColorHex = "#FFF"
};
context.Roles.AddOrUpdate(userRole);
}
}
} }