summaryrefslogtreecommitdiff
path: root/Project-Unite/Migrations/Configuration.cs
blob: 3f3fa5701782152c9a3f57d01ff60ee5704a5ae0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace Project_Unite.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<Project_Unite.Models.ApplicationDbContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = true;
            ContextKey = "Project_Unite.Models.ApplicationDbContext";
        }

        protected override void Seed(Project_Unite.Models.ApplicationDbContext context)
        {

            var adm = new Models.Role
            {
                Id = "administrator",
                ColorHex = "#FF0000",
                Description = "These are the admins of the website - This is a persistent group and cannot be deleted.",
                Priority = context.Roles.Count() + 1,
                Name = "Administrators"
            });
            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);


        }

    }
}