Click here to Skip to main content
15,887,331 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CurrentFinancialMovementData movementData = keys.OrderByDescending(s => s.LatestReserveDate ?? s.LatestRecoveryReserveDate).ThenByDescending(x => x.ReserveDaySequence).First();

CurrentFinancialMovementData movementDataReserve = keys.Where(s => s.AmountType == (short)StaticValues.AmountType.Reserve).OrderByDescending(a => a.LatestReserveDate).ThenByDescending(x => x.ReserveDaySequence).FirstOrDefault();

CurrentFinancialMovementData movementDataRecoveryReserve = keys.Where(s => s.AmountType == (short)StaticValues.AmountType.RecoveryReserve).OrderByDescending(a => a.LatestRecoveryReserveDate).ThenByDescending(x => x.ReserveDaySequence).FirstOrDefault();


I want to check if my movementData AmountType.Reserve then it must take LatestReserveDate and if my movementData is AmountType.RecoveryReserve than it should take LatestRecoveryReserveDate. I want to handle this situation in movementData. Can anyone help me in this ?

What I have tried:

I tried:
if (keys.Any(s => s.AmountType == (short)StaticValues.AmountType.Reserve))
{ CurrentFinancialMovementData movementData = keys.OrderByDescending(s => s.LatestReserveDate).ThenByDescending(x => x.ReserveDaySequence).First();
}
else if (keys.Any(s => s.AmountType == (short)StaticValues.AmountType.RecoveryReserve))
{ CurrentFinancialMovementData movementData = keys.OrderByDescending(s => s.LatestRecoveryReserveDate).ThenByDescending(x => x.ReserveDaySequence).First();
}
Posted
Updated 1-Mar-19 9:29am
v2

1 solution

I would do it this way:
C#
CurrentFinancialMovementData movementData = null;
{
    CurrentFinancialMovementData movement1 = keys.OrderByDescending(s => s.LatestReserveDate)
                                                 .ThenByDescending(x => x.ReserveDaySequence)
                                                 .FirstOrDefault(x=>x.AmountType == StaticValues.AmountType.Reserve);
    CurrentFinancialMovementData movement2 = keys.OrderByDescending(s => s.LatestRecoveryReserveDate)
                                                 .ThenByDescending(x => x.ReserveDaySequence)
                                                 .FirstOrDefault(x=>x.AmountType == StaticValues.AmountType.RecoveryReserve);
    movementData = (movement == null) ? movement2 : movement;
}

// caveat - there's still a chance that movementData could be null, but it's 
// handled gracefully in the process of determining that fact, and what you 
// do with that info is up to you.
 
Share this answer
 
v3
Comments
Maciej Los 3-Mar-19 10:59am    
5ed!
Member 9956700 4-Mar-19 23:29pm    
movementData = (movementData == null) ? movementData2 : movementData;

What is movementData2? where i need to define it.
#realJSOP 5-Mar-19 5:19am    
Oops, fixed it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900