diff --git a/backend/Infrastructure/Database/Seeding/SeedingService.cs b/backend/Infrastructure/Database/Seeding/SeedingService.cs index af642b5..33a36a8 100644 --- a/backend/Infrastructure/Database/Seeding/SeedingService.cs +++ b/backend/Infrastructure/Database/Seeding/SeedingService.cs @@ -36,23 +36,23 @@ public async Task SeedContacts() { logger.LogInformation("Seeding contacts to the database."); - Result> getContactsResult = await excelService.GetContacts(); - - if (getContactsResult.IsFailure) + if (await context.Contacts.AnyAsync()) { + logger.LogWarning( + "Contacts already exists in the database. Aborting process." + ); return; } - List contacts = getContactsResult.Value; + Result> getContactsResult = await excelService.GetContacts(); - if (await context.Contacts.AnyAsync()) + if (getContactsResult.IsFailure) { - logger.LogWarning( - "Contacts already exists in the database. Aborting process." - ); return; } + List contacts = getContactsResult.Value; + context.AddRange(contacts); await context.SaveChangesAsync();