I am trying to create a sort function that intelligently sorts our embroidery design schedule. Orders have Id's and might have 2 or 3 designs per order. Each list entry corresponds to one design. Designs with the same name may also appear across multiple orders, so design 'Manchester Utd Crest' may appear on order 123456 and order 55555
I want to sort by the design names first (string) and then by OrderId's (int). So I want all my design names (e.g. Manchester Utd Crest) to stay together on our schedule. However, if there is another design on that same order, I want the second design in the order to appear below the first design, even though it has a different name.
So I would end up with something like this:
Here is my code so far: it only sorts by OrderId, then by Design Name. I need it to sort by Design Names, but also make sure OrderIds that are the same always stay together in the list as well, which it doesn't do right now:
embroideryJobs.Sort((EmbroideryJob a, EmbroideryJob b) =>
{
if (a.OrderId != b.OrderId)
return a.OrderId.CompareTo(b.OrderId);
if (a.DesignProcessData[0].Name != b.DesignProcessData[0].Name)
return a.DesignProcessData[0].Name.CompareTo(b.DesignProcessData[0].Name);
return 0;
});