0

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.

2
  • why not change ur string such that 6 Mail - June 1, 2018 can be written as 01062018:6 Mail like that, here 01 represent 1st date, 06 represent June and 2018 the year and then sort it as usual on starting on their numbers Commented Mar 9, 2018 at 16:44
  • Is your problem that you just need the ThenBy descending, too? Commented Mar 9, 2018 at 16:44

1 Answer 1

4
activites = activites .OrderByDescending(a => a.StageId) .ThenByDescending(d => DateTime.Parse(d.InteractionDate)).ToList(); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.