I am trying to implement custom sorting for a functionality that goes like the below: A list of users (First Middle Last name combination)where middle name is optional. Here are a few criterias that I have for sorting:
1-first,middle,last
2-first,last,middle
3-last,middle,first
4-last,first,middle
I tried using linq's orderby followed by then but it wont work that way coz as i get the list of users ,i am converting the list of users to IEnumerable & pass this to the view to bind it to dropdownlist. Here is my final list assigned to the viewmodal:
viewModel.Users= users
.Select(usr=> new SelectListItem()
{
Text = $"{usr.FirstName} {usr.MiddleName} {usr.LastName}",
Value = $"{usr.FirstName} {usr.MiddleName} {usr.LastName}"
}).ToArray();
So the question is how do i sort IEnumerable items based on the above criteria?
I am aware that this wont work with the existing sorting & I need some help in custom sorting i.e. more of creating an extension method that will be able to sort based on the above critera. Any help is appreciated. Thanks.