Exemple #1
0
 public UserRole(User user, Role role)
 {
     if (user == null)
     {
         throw new ArgumentNullException("user");
     }
     if (role == null)
     {
         throw new ArgumentNullException("role");
     }
     User = user;
     Role = role;
 }
Exemple #2
0
        private void FixupRole(Role previousValue)
        {
            if (previousValue != null && previousValue.UsersInRoles.Contains(this))
            {
                previousValue.UsersInRoles.Remove(this);
            }

            if (Role != null)
            {
                if (!Role.UsersInRoles.Contains(this))
                {
                    Role.UsersInRoles.Add(this);
                }
                if (RoleId != Role.Id)
                {
                    RoleId = Role.Id;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Adds the role.
        /// </summary>
        /// <param name="role">The role.</param>
        public void AddRole(Role role)
        {
            if (role == null)
                throw new BusinessException("Role must be specified.");

            if (UserRoles.Select(ur => ur.Role.Id).Contains(role.Id))
                throw new BusinessException("User is already assigned to role: " + role.RoleName);

            UserRoles.Add(new UserRole(this, role));
        }