I have wrote a really messy code, just because I did not had an idea how to loop through the multiple list of objects.
Code is working what it suppose to do, but I am not confident with it. Does someone has an idea how this kind of code can be refactored so it is more readable?
foreach (var outlet in merchant.Outlets)
{
if (outlet != null)
{
foreach (var terminal in merchant.Terminals)
{
if (terminal != null)
{
foreach (var agreement in terminal.AssociateAgreements)
{
var bankInfo = new Bank();
if (agreement != null)
{
bankInfo.UniqueID = AgreementUniqueCode + agreement.ID;
bankInfo.BankBIC = agreement.BankAccountInformation.SwiftBIC;
bankInfo.BankName = agreement.BankAccountInformation.BankName;
bankInfo.Address =
AddressEntityToAddress(agreement.BankAccountInformation.BankAddress,
BankingType);
bankInfo.type = BankType;
}
banksAccountInformation.Add(bankInfo);
}
}
}
}
}