How can I sort an array of Accounts that need to be sorted on an array of PersonRoles that say which role an associated person has with that account?
For example,
Bob is the Owner (O) of account 12, the Co-signer (CO) of account 123, and the Beneficiary of account 1234.
Joe is the Owner (O) of account 123 and account 1234 the Beneficiary (BE) of account 12.
How would I sort the array of Accounts for Bob in the order of Owners (O) first, then Co-signer('CO'), then Beneficiary (BE) in that order.
Accounts object structure
Accounts
{
AccountNumber: 12,
PersonRoles: [
{
AccountRoleCode: "O",
AccountRoleDescription: "Owner",
Person: "Bob"
},
{
AccountRoleCode: "CO",
AccountRoleDescription: "Co-Signer",
Person: ""
},
{
AccountRoleCode: "BE",
AccountRoleDescription: "Beneficiary",
Person: "Joe"
},
],
Balance: 5.00
},
{
AccountNumber: 123,
PersonRoles: [
{
AccountRoleCode: "O",
AccountRoleDescription: "Owner",
Person: "Joe"
},
{
AccountRoleCode: "CO",
AccountRoleDescription: "Co-Signer",
Person: "Bob"
},
{
AccountRoleCode: "BE",
AccountRoleDescription: "Beneficiary",
Person: null
},
],
Balance: 100.00
},
{
AccountNumber: 1234,
PersonRoles: [
{
AccountRoleCode: "O",
AccountRoleDescription: "Owner",
Person: "Joe"
},
{
AccountRoleCode: "CO",
AccountRoleDescription: "Co-Signer",
Person: null
},
{
AccountRoleCode: "BE",
AccountRoleDescription: "Beneficiary",
Person: "Bob"
},
],
Balance: 10000000.00
}
Original array of Accounts listed under Bob returned from API.
[1234, 12, 123]
Desired Sorted array.
[12, 123, 1234]
My initial approach is to use LINQ on the array, but I'm unsure how to loop through the Accounts[] and then loop through the PersonRoles[] to sort the Accounts[] based on the PersonRoles[].
Does this need like a double LINQ query? Or would another approach be better?