0
Hello, I want to list the elements of the class called, but the Status is of type Enum, when trying to convert to string, appears the message: "It is not possible to implicitly convert type 'string' into Enums.Status". Code:
public async Task<IEnumerable<ChamadoViewModel>> ObterTodos()
{
var chamados = await _repository.ObterTodos();
var chamadosView = new List<ChamadoViewModel>();
foreach(var chamado in chamados)
{
chamadosView.Add(new ChamadoViewModel
{
IdOrigemUsuario = chamado.IdOrigemUsuario,
IdUsuario = chamado.IdUsuario,
IdOperadora = chamado.IdOperadora,
DataChamado = chamado.DataChamado,
HoraChamado = chamado.HoraChamado,
Solicitadora = chamado.Solicitadora,
NomeProfissional = chamado.NomeProfissional,
Motivo = chamado.Motivo,
Erro = chamado.Erro,
Status = chamado.Status.ToString()
});
}
}
"Cannot implicitly convert string to Enums.Status" by the message, in that
ChamadoViewModel
the PropertyStatus
is an Enum and not string, hence it is giving error. It puts the definition of the class in the question and also of the class that is the type of the variablechamados
, but I think you need to convert one One to another One. If they have the same values, it could convert to int before, but if they are different, and this would be the most recommended, would be to make a method that maps the values– Ricardo Pontual
@fanwraunes something new?
– Leandro Angelo