public Role AddRole(string roleName) { Role role = new Role() { Name = roleName }; return AddRole(role); }
public Role AddRole(Role role) { if (RoleExists(role)) throw new ArgumentException(TooManyRole); return entities.Roles.Add(role); }
public IQueryable<User> GetUsersForRole(Role role) { if (!RoleExists(role)) throw new ArgumentException(MissingRole); return from user in entities.Users where user.RoleId == role.RoleId orderby user.UserName select user; }
public bool RoleExists(Role role) { if (role == null) return false; return (entities.Roles.SingleOrDefault(r => r.RoleId == role.RoleId || r.Name == role.Name) != null); }
public Role DeleteRole(Role role) { if (!RoleExists(role)) throw new ArgumentException(MissingRole); if (GetUsersForRole(role).Count() > 0) throw new ArgumentException(AssignedRole); return entities.Roles.Remove(role); }