2
I have a Shopping List(Shoppingitems) like this:
Descricao: Padaria Campobelo
Valor: -24.00
Data: 06-03-2019
Categoria: Alimentacao
Descricao: Uber tecnologia
Valor: -24.00
Data: 07-03-2019
Categoria: Transporte
Descricao: Uber tecnologia
Valor: -30.00
Data: 08-03-2019
Categoria: Transporte
I would like to know how to get to the category with the highest expense, I tried to do as follows:
var result = (from item in ListShoppingItens
group item by item.Categoria into cat
select new ShoppingItens
{
Valor = cat.Sum(x => x.Valor)
}).ToList();
But it is returning only one category, in the case of travel
My class is like this:
public class ShoppingItens
{
public enum Category
{
VIAGEM,
DIVERSAO,
ALIMENTACAO,
HOSPEDAGEM,
VESTUARIO,
TRANSPORTE,
HIGIENE,
SEMCATEGORIA,
}
public DateTime Data { get; set; }
public string Descricao { get; set; }
public decimal Valor { get; set; }
public Category Categoria { get; set; }
}
because the value is negative? what is the output you want (for example)? because in the list you gave of sample you placed a category that does not exist (supermarket)?
– vik
The value is negative because it’s the amount he spent on that particular purchase, that is, the money that came out, if there is a positive value it means he received the money.
– Leonardo Lima