/// <summary> /// Adds user to role /// </summary> /// <param name="role"></param> /// <param name="user"></param> public void AddUserToRole(Role role, User user) { if (!role.Users.Contains(user)) { role.Users.Add(user); AddRoleToUser(user, role); } }
/// <summary> /// Adds role to user /// </summary> /// <param name="user"></param> /// <param name="role"></param> public virtual void AddRoleToUser(User user, Role role) { if (!user.Roles.Contains(role)) { user.Roles.Add(role); AddUserToRole(role, user); } }
/// <summary> /// Creates role which name is "rolename" /// </summary> /// <param name="roleName"></param> public void CreateRole(string roleName) { if (RoleExists(roleName)) return; var role = new Role { RoleName = roleName }; _rolesContext.Add(role); }