I have a list with attributes, of which I have the field of evaluations, containing: Excellent, Good, Regular, Bad, and Poor. The information for this field I get from consuming a REST API using JSON.
Example:
IEnumerable<minhaEntidade> minhaLista = _respositorio.ConsumirAPI();
foreach (var item in minhaLista)
{
Retorno.Add(new minhaNovaEntidade()
{
Nome = item.NomeCompleto,
Endereco = item.EnderecoCompleto,
Avaliacao = item.AvaliacaoDesempenho
});
}
If I do:
return Retorno.OrderBy(x => x.Avaliacao);
I'll have the list sorted by performance ratings in alphabetical order.
However, I need to sort the list by following the precedence criteria: Excellent, Good, Fair, Bad, and Poor.
That is, all Names and Addresses that have first been evaluated as Excellent, then Good, then Regular, then Bad, then Poor. In this order.
I've tried to create a Type-Safe Enum Pattern
to compare the list obtained with my Type-Safe Enumerator , example:return Retorno.OrderBy(x => MeuEnumerador().CompareTo(x.Avaliacao));
or ...
return Retorno.Sort((x,y) => x.Avaliacao.CompareTo(MeuEnumerador().ToString()))
But it did not work and / or gives error.
Questions:
Has anyone ever had to do something similar to this my problem using C #?
Or, do you have any implementation suggestions for what I'm looking for?
Remembering that the information does not come from a database (which would be easy to solve), but a JSON API, and the field is just a string.