CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
namespace ConsoleApp1
{
public class Program
{
public static void Main()
{
var respostaProcedure = new List<DB>()
{
new DB(111342, 1, 1, true, false, false),
new DB(111342, 1, 2, true, true, true),
new DB(111342, 1, 3, true, true, true),
};
var respostaMapeada = respostaProcedure
.GroupBy(x => new { x.CodUs, x.iA })
.Select(x => new Login
{
CodUs = x.Key.CodUs,
iA = x.Key.iA,
LoginPers = x.Select(l => new LoginPer { bC = l.bC, bD = l.bD, bE = l.bE, iB = l.iB }).ToList()
});
Console.WriteLine(JsonConvert.SerializeObject(respostaProcedure));
}
}
public class DB
{
public DB(int CodUs, int iA, int iB, bool bC, bool bD, bool bE)
{
this.CodUs = CodUs;
this.IA = iA;
this.iB = iB;
this.bC = bC;
this.bD = bD;
this.bE = bE;
}
public int CodUs;
public int iA;
public int iB;
public bool bC;
public bool bD;
public bool bE;
public int IA;
}
public class Login
{
public int CodUs;
public int iA;
public ICollection<LoginPer> LoginPers { get; set; }
}
public class LoginPer
{
public int iB;
public bool bC;
public bool bD;
public bool bE;
}
}