private static List<Role> AddTenRoles() { List<Role> roleCollection = new List<Role>(); for (int i = 0; i < 9; i++) { Role role = new Role(); roleCollection.Add(role); } return roleCollection; }
public override void CreateRole(string roleName) { if (!string.IsNullOrEmpty(roleName)) { using (DataContext Context = new DataContext()) { Role Role = null; Role = Context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName); if (Role == null) { Role NewRole = new Role { Id = Guid.NewGuid(), RoleName = roleName }; Context.Roles.Add(NewRole); Context.SaveChanges(); } } } }
//create a new role with a given name public override void CreateRole(string rolename) { if (rolename.Contains(",")) throw new ArgumentException("Role names cannot contain commas."); if (RoleExists(rolename)) throw new ProviderException("Role name already exists."); try { var role = new Role { ApplicationName = ApplicationName, RoleName = rolename }; roles.Update(role); roles.SaveChanges(); } catch (Exception ex) { if (WriteExceptionsToEventLog) WriteToEventLog(ex, "CreateRole"); else throw; } }
public User() { PersonalInfo = new PersonalInfo(); Role = new Role(); }
public virtual void RemoveRole(Role role) { role.UsersInRole.Remove(this); Roles.Remove(role); }
public virtual void AddRole(Role role) { role.UsersInRole.Add(this); Roles.Add(role); }