/// <summary> /// Saves a single User. Do not use this Method in combination with GetUsers/SetUsers! /// </summary> /// <param name="account">Users Account. If it does not exists a new User is created</param> /// <param name="password">Users password</param> /// <param name="firstName">Users First Name</param> /// <param name="surName">Users Sur Name</param> /// <param name="roles">ArrayList of Roles</param> /// <param name="userId">Users Id</param> public static void SaveUser(string account, string password, string firstName, string surName, string email, ArrayList roles, Guid userId) { if (null == account) { throw new ArgumentException(Language.GetText("exception_NullReferenceParameter"), "account"); } if (null == roles) { throw new ArgumentException(Language.GetText("exception_NullReferenceParameter"), "roles"); } Users u = Users; Users.UserRow user = u.User.FindBylogin(account.ToLower(CultureInfo.CurrentCulture)); if (user == null) { user = u.User.AddUserRow(account, password, firstName, surName, email, userId); } else { if (!string.IsNullOrEmpty(password)) { user.password = password; } user.firstName = firstName; user.surName = surName; user.email = email; user.id = userId; } // Delete old Roles foreach (Users.UserRoleRow r in user.GetUserRoleRows()) { r.Delete(); } // Add new Roles foreach (string newRole in roles) { u.UserRole.AddUserRoleRow(u.Role.FindByname(newRole), user); } SetUsers(u); }
/// <summary> /// Returns the current Users Roles. /// </summary> /// <param name="account">Users account</param> /// <returns>string array of the users roles. Returns a empty array if the user is not found</returns> public static string[] GetRoles(string account) { if (null == account) { throw new ArgumentException(Language.GetText("exception_NullReferenceParameter"), "account"); } Users u = Users; Users.UserRow user = u.User.FindBylogin(account.ToLower(CultureInfo.CurrentCulture)); if (user == null) { return(new string[0]); } Users.UserRoleRow[] roles = user.GetUserRoleRows(); string[] result = new string[roles.Length]; for (int i = 0; i < roles.Length; i++) { result[i] = roles[i].RoleRow.name; } return(result); }