Exemplo n.º 1
0
        public void CreateUser(int roleID, string username, string password)
        {
            var roles = _roleDAO.GetRoles();
            var ids   = new List <int>();

            foreach (var role in roles)
            {
                ids.Add(role.RoleID);
            }
            if (!IsValidID(roleID, ids))
            {
                throw new ArgumentException("No such user found.");
            }
            else if (username == null || username == "")
            {
                throw new ArgumentException("Username must not be empty.");
            }
            else if (UserAlreadyExists(_userDAO.GetUsers(), username))
            {
                throw new ArgumentException("User with such a name already exists.");
            }
            else if (username.Length > 50)
            {
                throw new ArgumentException("The maximum length of username must be 50 characters or below.");
            }
            else if (!IsVarcharString(username))
            {
                throw new ArgumentException("Username must be in ASCII.");
            }
            else if (password == null || password == "")
            {
                throw new ArgumentException("Password must not be empty.");
            }
            else if (password.Length > 50)
            {
                throw new ArgumentException("The maximum length of password must be 50 characters or below.");
            }
            else if (!IsVarcharString(password))
            {
                throw new ArgumentException("Password must be in ASCII.");
            }
            else
            {
                _userDAO.CreateUser(roleID, username, password);
            }
        }
Exemplo n.º 2
0
 public IEnumerable <Role> GetRoles()
 {
     return(_roleDAO.GetRoles());
 }