I have range values in a list that I want to order in a descending by date, where property values are the same.
I cannot just sort everything as it is sorted by an Id first ThenBy date.
So my first step is as follow
activites = activites.OrderByDescending(a => a.StageId).ThenBy(d => DateTime.Parse(d.InteractionDate)).ToList(); Problem is where the id's are the same (see below)
- 8 Scheduled Call - June 12, 2018
- 7 Activation - June 4, 2018
- 7 Activation - June 5, 2018
- 7 Activation - June 6, 2018
- 6 Mail - June 1, 2018
and I want it sorted like this.
- 8 Scheduled Call - June 12, 2018
- 7 Activation - June 6, 2018
- 7 Activation - June 5, 2018
- 7 Activation - June 4, 2018
- 6 Mail - June 1, 2018
I tried this as the next step which was not successful. The field value (StageName) can change and doesn't always stay the same.
var stages = activities.Select(s => s.StageName).ToList(); foreach(var s in stages) { activities.Where(a => a.StageName== s).OrderByDescending(a => DateTime.Parse(a.InteractionDate)).ToList(); } return activities; In the code, 'stages' represent Scheduled Call, Activation etc.
ThenBydescending, too?