title: MVC4 : adding roles in database
body: <p>I have a project called <code>Authorization</code> with <code>CodeFirstRoleProvider</code> class that inherits from default <code>RoleProvider</code></p>
  
  <pre><code>public class CodeFirstRoleProvider : RoleProvider
  {
      public override void CreateRole(string roleName)
          {
              if(string.IsNullOrEmpty(roleName)) return;
              using(var context = new SISContext())
              {
                  var role = context.Roles.SingleOrDefault(rl =&gt; rl.RoleName == roleName);//Roles table exists in database 
                  if(role == null)
                  {
                      var newRole = new Role
                                        {
                                            RoleId = Guid.NewGuid(),
                                            RoleName = roleName
                                        };
                      context.Roles.Add(newRole);
                      context.SaveChanges();
                  }
              }
          }
  }
  </code></pre>
  
  <p>In my other project <code>WebPortal</code> I want to use above method in let's say following way</p>
  
  <pre><code>var _role = new CodeFirstRoleProvider();
              _role.CreateRole("Admin");
              _role.CreateRole("NonAdmin");
  </code></pre>
  
  <p>now where do I need to place this code in my <code>webportal</code>? so that these roles gets added to database for the first time when the application runs. </p>
  
  <p>Suppose this program runs for first time and someone clicks the register button I want to have a dropdownlist with above roles mentioned. So, these roles need to be in database before register is clicked.</p>
  
  <p>Once the roles are in database I don't need to worry for the accessing these values in future. 
  One way would be manually writing the value in database but I don't want to do that, since I have this function I can use.</p>