PROBLEM:
If I put SaveChangesAsync outside of the loop, it changes only the last data which was put with _context.Add(attdef);
Why is that so?
First I thought it's because I have autoIncrement, but when I disabled it, It still did not work.
Using SaveChanges instead of SaveChangesAsync does not fix problem aswell.
But updating data works well.
GameController.cs
for (int i = 0; i < editViewModel.TowerAttack.Count; i++)
{
tower = _context.Tower.First(m => m.TowerId == editViewModel.TowerId[i]);
tower.Attack -= editViewModel.TowerAttack[i];
_context.Update(tower);
attdef.Id = 0; // AutoIncrement
attdef.Amount = attackSum;
_context.Add(attdef);
}
await _context.SaveChangesAsync();