I've a method called by my controller and i'm trying to add new value during the iteration
public async Task<MyResult> GetItems(int itemId) {
try
{
//returns a lists of items
var resList = await _unit.repository.GetAll(x => x.ItemId.Equals(itemId));
if(resList.Count() == 0)
throw new Exception(err.Message);
//Here i need to list the sub-items, but the method returns async
resList.ToList().ForEach(async res => {
switch (res.Type)
{
case Itemtype.None :
res.SubItems = await _unit.repository.GetAll(y => y.ItemId(res.ItemId));
break;
case Itemtype.Low :
//get from another place
break;
}
});
return new MyResult {
res = resList
};
}
catch (Exception ex)
{
throw ex;
}
}
It was shown my Items, but without the sub-items