I am trying to store data in database using EF my code run fine but its not storing data

if (response.IsSuccessStatusCode)
{
var json = await response.Content.ReadAsStringAsync();
var jsonObject = JsonConvert.DeserializeObject<JToken>(json);
if (jsonObject != null && jsonObject.HasValues)
{
List<Initiative_Goal> ahaInitiative = jsonObject["initiatives"].
Select(x =>
{
Initiative_Goal initiative = new Initiative_Goal();

initiative.InitiativeID = x.Value<long>("value");

return initiative;
}).ToList();

foreach (Initiative_Goal initiatives in ahaInitiative)
{
var existingRecord = await context.Initiative_Goal.FirstOrDefaultAsync(x => x.InitiativeID == initiatives.InitiativeID);

if (existingRecord == null)
{
fullAPIList.Add(initiatives);
}
else
{
existingRecord.InitiativeID = initiatives.InitiativeID;

//existingRecord.Description = initiatives.Description;
}
}

await context.SaveChangesAsync();
}
else
{
Console.WriteLine("No Aha data found in the response.");

}
Was this page helpful?