I have a grouped variable called groupValues
this groupValues has the following
var groupValues = allValues.Current.GroupBy(x => new { x.Id })
.Select(g => new
{
Id1 = g.Select(x => x.Id1),
Names = string.Join(", ", g.Select(x =>
x.Name).Distinct().ToList()),
allFields = g
});
now in the response
i want to retrieve this
"Values": [
{
"id": 2,
"names": "name1, name2, name3",
"totalPrice": "45",
details:[
{
"name": "name1",
"name_price": "25"
}
{
"name": "name2",
"name_price": "30"
}
{
"name": "name3",
"name_price": "null"
}
}
]
I'm having difficulty in retrieving the details in this format
What I have tried:
AllValues allValues = await service.getAllValues(request);
<pre>
var groupValues = allValues.Current.GroupBy(x => new { x.Id })
.Select(g => new
{
Id1 = g.Select(x => x.Id1),
Names = string.Join(", ", g.Select(x =>
x.Name).Distinct().ToList()),
allFields = g
});
List<Value> valueList = new List<Value>();
foreach (var y in groupValues)
{
var totalPrice = y.allFields.Select(x => x.Price).Sum();
valueList.Add(new Response(y.Names,totalPrice))
}
How to get the details part?
i made a class for details, but i don't know how to do it to appear in the response