I have two text files with the following data (separated by tabs):
CLIENT
ID_CLIENTE CLIENTE MERCADO
1198 CTA G
1285 FGF B
1112 EJESA B
1131 ESPERANZA F
1150 NORP B
1141 LUQUE B
1151 TUCU F
1235 BERNV G
SPENDING
FECHA ID_CLIENTE GASTO
01/08/2017 1198 25647
01/08/2017 1285 4885
01/08/2017 1112 71987
01/08/2017 1131 1000
01/08/2017 1150 5
01/08/2017 1141 98
01/08/2017 1151 84
01/08/2017 1235 5899
02/08/2017 1198 257
02/08/2017 1285 4885
02/08/2017 1112 1987
02/08/2017 1131 1489
02/08/2017 1150 5489
02/08/2017 1141 8
02/08/2017 1151 841
02/08/2017 1235 589
03/08/2017 1198 257
03/08/2017 1285 4
03/08/2017 1112 1987
03/08/2017 1131 1589
03/08/2017 1150 2489
03/08/2017 1141 89
03/08/2017 1151 841
03/08/2017 1235 589
Now create a class for each file and individualize the data.
public class Cliente
{
public int IdCliente { get; set; }
public string Nombre { get; set; }
public string Mercado { get; set; }
}
public class Consumo
{
public int IdCliente { get; set; }
public DateTime Fecha { get; set; }
public int Gasto { get; set; }
}
What I need to do is take the maximum cost of each client and print it in a text file. I have to do it with Dictionaries.
Statement:
List<Cliente> Clientes;
List<Consumo> Consumos;
Dictionary<int, Cliente> dClientes;
Dictionary<int, List<Consumo>> dConsumos;
#region Constructor
public Reporte(List<Cliente> Clientes, List<Consumo> Consumos)
{
this.Clientes = Clientes;
this.Consumos = Consumos;
}
#endregion
Loading data to Dictionaries:
dClientes = Clientes.ToDictionary(c => c.IdCliente, v => v);
dConsumos = Consumos.Where(c => dClientes.Keys.Contains(c.IdCliente)).
GroupBy(c => c.IdCliente).
ToDictionary(c => c.Key, v => v.ToList<Consumo>());
My question is: How I relate (INNER JOIN to ID_CLIENTE) both dictionaries to be able to perform this operation (greater expense) or what kind of methods are used in these cases. If you can perform this operation in a separate method and then implement it would be better.
EXPECTED DEPARTURE
CLIENTE MERCADO MAXIMO GASTO
CTA G 2547
FGF B 4885
EJESA B 71987
ESPERANZA F 1589
NORP B 5489
LUQUE B 98
TUCU F 841
BERNV G 5899
Greetings, any questions or answers to the question I am available.