I need to return response of each API call inside ForEach loop without waiting for end of it.
First Api to get data from SharePoint and call another Api to update website database:
[HttpGet]
[Route("GetAllFaqs")]
public async Task<ApiResult<List<FaqModel>>> GetAllFaqs()
{
ApiSuccessResult<List<FaqModel>> faqs = await sharepointConnector.GetAllFaqsAsync();
foreach (var faq in faqs.Response)
{
// Here I want to return response of this Api call
// so I could show on client side one by one
await UpdateFaq(faq);
}
return faqs;
}
Another Api to update website database:
[HttpPost]
[Route("UpdateFaq")]
public async Task<ApiResult<FaqSyncResult>> UpdateFaq(FaqModel model)
{
ApiSuccessResult<FaqSyncResult> result = await websiteConnector.SyncFaq(model);
return result;
}
Is it possible to return response inside ForEach loop without stop it and also without waiting for the end?