0
I have one that returns a table in Ienumerable and I have a certain column that returns values "A" for Active, "C" for Canceled and so on. I would like to convert these values to the correct one before arriving in the view. Type instead of "A" would appear to the "Active" user. How do you do that? Any help is welcome.
It would be something like the code below, more applied in a Ienumerable list.
public string GetStatusPagamento(int fileCodigo)
{
var statusPgto = _context.GetFileByFileCode(fileCodigo).Select(s =>
s.StatusPagamento).FirstOrDefault();
switch (statusPgto.ToString())
{
case "A":
return "Ativo";
case "D":
return "Ativo";
case "E":
return "Cancelado";
case "M":
return "Reembolsado";
case "R":
return "Ativo";
case "X":
return "Cancelado";
default:
return "Indefinido";
}
}
It is very difficult to answer because anyone who reads your question can imagine your code differently. You need to ask the questions in detail, have a review because there are some words missing from the question, add your code and learn more about how to ask here: https://answall.com/help/how-to-ask
– Renan
I added an example code. I needed to do something like this, but in a list like Ienumerable.
– Nilson Martins
@Nilsonmartins You want to do this "conversion" for all items from
statusPgto
. That’s it?– Jéf Bueno
What is the type of
statusPgto
?– ramaral
This conversion would be for all items. It is a string list "Ienumerable<string>"
– Nilson Martins
Okay, it was in the text of the question, I didn’t notice. What led me to question was the
statusPgto.ToString()
, used in the code.– ramaral
He considered the idea of overriding the . Tostring() of the [Statuspagamento] to make this conversion?
– Ronaldo Araújo Alves
@Ronaldoaraújoalves and if in another context you need another way? In fact every time someone uses this method to format data a panda dies somewhere https://answall.com/q/212754/101
– Maniero
Well noted, @Maniero...you’re right. + 1
– Ronaldo Araújo Alves
Thanks @Ronaldoaraújoalves, override Tostring was the solution I was looking for.
– Nilson Martins
Thanks @Maniero, override Tostring was the solution I was looking for.
– Nilson Martins