public IActionResult GetAllToGroupedData() { GroupedData groupedData; var data = new List <GroupedData>(); var groups = _mealService.GetAllGroupCode(out bool result, out string message); foreach (var group in groups) { groupedData = new GroupedData(); groupedData.text = group.GroupCode.ToUpper(); var children = _mealService.GetByGroupCode(group.GroupCode, out result, out message); foreach (var child in children) { groupedData.children.Add(new ChildItem() { id = child.Id.ToString(), text = child.Name }); } data.Add(groupedData); } return(new OkObjectResult(new GenericResult(result, message, data))); }