4
I need to return in a REST data of two tables, to be consumed in an Android/IOS App, developed with Xamarin. As I return a DTO, I thought to bring in this DTO data of two tables, but I find this somewhat Gambi. The other solution would be to return two DTO, then two services, one filling the Listview of Release and the other filling the Listview of Items. I don’t know what would be the best approach. Below my DTO.
public class LiberacaoItensDTO
{
//Mapeamento dos campos, pois estava dando erro de cast e assim resolveu
public LiberacaoItensDTO()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<LiberacaoItensDTO, Liberacao>()
.ForMember(d => d.DataLib, opt => opt.MapFrom(src => DataLib.ToString()));
});
}
//Dados da tabela Liberação
public int IdLiberacao { get; set; }
[DefaultValue(0)]
public int IdOrcamento { get; set; }
[DefaultValue(0)]
public int IdVendedor { get; set; }
public string Vendedor { get; set; }
public int IdFilial { get; set; }
public string Filial { get; set; }
[DefaultValue(0)]
public float? DataLib { get; set; }
public int IdCliente { get; set; }
public string Cliente { get; set; }
public string TipoVenda { get; set; }
[DefaultValue(0)]
public float Juros { get; set; }
[DefaultValue(0)]
public float Desconto { get; set; }
[DefaultValue(0)]
public double Vencimento { get; set; }
[DefaultValue(0)]
public double Acrescimo { get; set; }
[DefaultValue(0)]
public float Entrada { get; set; }
//Dados da tabela de ItensLib
public int IdProduto { get; set; }
public string Produto { get; set; }
[DefaultValue(0)]
public float Qtde { get; set; }
[DefaultValue(0)]
public float Unitario { get; set; }
[DefaultValue(0)]
public float CustoDiario { get; set; }
[DefaultValue(0)]
public double UltCondicao { get; set; }
[DefaultValue(0)]
public float Total { get; set; }
}
Method to bring DTO into service
public List<LiberacaoDTO> getAutoriza(int idorcamento)
{
var lista = contexto.Liberacoes??????? Faria um Join com as duas tabelas, liberacao e itenslib
.Where(lib => lib.IdOrcamento == idorcamento)
.Select(lib => new LiberacaoItensDTO
{
//Aqui coloco os campos retornados
}).ToList();
return lista;
}
The problem is in the fields float or double. It gives me this error:
The specified cast from a materialized 'System.Double' type to the 'System.Single' type is not valid.
– pnet
Problem? You didn’t mention any cast problem in the question.
– Gabriel Coletta
I know, for the posted question is settled. The problem is when I put fields float, a problem that I was passing, disappeared, I thought I had solved and now started again, so the comment. As for the answer to that question, okay, it’s solved.
– pnet