I'm just wondering if there is a better way of executing multiple methods depending on a value?
I have a Property that gets the NumberOflegs. NumberOfLegs can have a value between 1-6. If the value is 1, it needs to execute InsertLeg1Details. If the value is 2, it needs to execute InsertLeg1Details and InsertLeg2Details, etc.
private void SaveLegs()
{
switch (NumberOfLegs)
{
case 1:
SaveDataALC.SaveFlight(InsertLeg1Details());
break;
case 2:
SaveDataALC.SaveFlight(InsertLeg1Details());
SaveDataALC.SaveFlight(InsertLeg2Details());
break;
case 3:
SaveDataALC.SaveFlight(InsertLeg1Details());
SaveDataALC.SaveFlight(InsertLeg2Details());
SaveDataALC.SaveFlight(InsertLeg3Details());
break;
case 4:
SaveDataALC.SaveFlight(InsertLeg1Details());
SaveDataALC.SaveFlight(InsertLeg2Details());
SaveDataALC.SaveFlight(InsertLeg3Details());
SaveDataALC.SaveFlight(InsertLeg4Details());
break;
case 5:
SaveDataALC.SaveFlight(InsertLeg1Details());
SaveDataALC.SaveFlight(InsertLeg2Details());
SaveDataALC.SaveFlight(InsertLeg3Details());
SaveDataALC.SaveFlight(InsertLeg4Details());
SaveDataALC.SaveFlight(InsertLeg5Details());
break;
case 6:
SaveDataALC.SaveFlight(InsertLeg1Details());
SaveDataALC.SaveFlight(InsertLeg2Details());
SaveDataALC.SaveFlight(InsertLeg3Details());
SaveDataALC.SaveFlight(InsertLeg4Details());
SaveDataALC.SaveFlight(InsertLeg5Details());
SaveDataALC.SaveFlight(InsertLeg6Details());
break;
}
}