/// <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> public static void SaveUser(string account, string password, string firstName, string surName, ArrayList roles) { Users u = GetUsers(); Users.UserRow user = u.User.FindBylogin(account.ToLower()); if (user == null) { user = u.User.AddUserRow(account, password, firstName, surName); } else { user.password = password; user.firstName = firstName; user.surName = surName; } // 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) { Users u = GetUsers(); Users.UserRow user = u.User.FindBylogin(account.ToLower()); 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); }