private string GetTransactionGroupNameUsingValue(TransactionGroupBy? group, List<Transaction> transactions) { if (group != null) { var transaction = transactions.FirstOrDefault(); switch (group) { case TransactionGroupBy.Category: return transaction.Category; case TransactionGroupBy.SubCategory: return transaction.SubCategory; case TransactionGroupBy.DateDay: return transaction.Date.ToString("yyyy/MM/dd"); case TransactionGroupBy.DateMonth: return transaction.Date.ToString("yyyy/MM"); case TransactionGroupBy.DateYear: return transaction.Date.ToString("yyyy"); case TransactionGroupBy.Name: return transaction.Name; case TransactionGroupBy.InputOutput: return transaction.Value > 0 ? "Receita" : "Despesa"; } } return null; }
public Expression<Func<Transaction, object>> GetGroupByExpression(TransactionGroupBy group, out string groupName) { switch (group) { case TransactionGroupBy.Category: groupName = "Categorias"; return f => f.Category; case TransactionGroupBy.SubCategory: groupName = "Sub-categorias"; return f => f.Category + "/" + f.SubCategory; case TransactionGroupBy.DateDay: groupName = "Dias"; return f => f.Date.ToString("yyyy/MM/dd"); case TransactionGroupBy.DateMonth: groupName = "Meses"; return f => f.Date.ToString("yyyy/MM"); case TransactionGroupBy.DateYear: groupName = "Anos"; return f => f.Date.ToString("yyyy"); case TransactionGroupBy.Name: groupName = "Nomes"; return f => f.Name; case TransactionGroupBy.InputOutput: groupName = "Receitas e despesas"; return f => f.Value > 0 ? "Receita" : "Despesa"; } groupName = "Nenhum"; return null; }