Exemple #1
0
 private void assertValidUserAndRole(Users user, Role role)
 {
     user.ReportIfNull("User cannot be null");
     role.ReportIfNull("Role cannot be null");
     if (user.ApplicationName != role.ApplicationName)
         throw new Exception(String.Format("Cannot add user {0} of {1} to {2} of {3}, because different application name", user, user.ApplicationName, role, role.ApplicationName));
 }
Exemple #2
0
        public UserRole AddUser(Users user)
        {
            user.ReportIfNull("Argument AddUser(user)");
            if (_userRoles.Contains(ur => ur.UserId.Equals(user.Id)))
                throw new Exception(String.Format("User {0} is already in {1}", user.Name, this.Name));

            var userRole = new UserRole(user, this);
            _userRoles.Add(userRole);
            return userRole;
        }
Exemple #3
0
 public UserRole RemoveUser(Users user)
 {
     user.ReportIfNull("Argument RemoveUser(user)");
     if (!_userRoles.Contains(ur => ur.UserId.Equals(user.Id)))
         throw new Exception(String.Format("User {0} is not in {1}", user.Name, this.Name));
     if (user.Name.Equals(Users.ADMINISTRATOR_USER) && this.Name.Equals(ADMINISTRATOR_ROLE))
         throw new Exception(String.Format("Cannot remove {0} from {1}", user, this));
     foreach (var ur in _userRoles)
     {
         if (ur.UserId.Equals(user.Id))
         {
             _userRoles.Remove(ur);
             return ur;
         }
     }
     return null;
 }