C#C
C#4y ago
malkav

✅ Sorting nested

So I've got this data model that looks something like this (some parts of the fields have been omitted as they are irrelevant)

public class UserMonth
{
  // ...
  public int Month {get;set;}
  public int Year {get;set;}
  public List<DaysWorked> DaysWorked {get;set;}
  // ...
}

public class DaysWorked
{
  public DateTime Date {get;set;}
  // ...
}


I'm probably thinking too hard here and that's why I'm missing something simple, so I came here for help

I want to do the following in my component:

I've got a List<UserMonth> in my component, and I want to render a table by week.
The user selects a month and a year they wish to view, and I am supposed to find the UserMonth that was selected (List<UserMonth>.Select(x => x.Month == SelectedMonth && x.Year == SelectedYear) .. should be easy enough)
Then I need to seperate the List<DaysWorked> into a nested list: List<List<DaysWorked>> where I sort each week's dates in its own list, and add that list to the list (but keep it sorted?) (Or if there is a better way I'd love to hear it)
and then I have to render basically for each week, its own table

So does anyone have any ideas on how to do this?
Was this page helpful?