Initial commit
هذا الالتزام موجود في:
12
Data/AppDbContext.cs
Normal file
12
Data/AppDbContext.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WondersAPI.Models;
|
||||
|
||||
namespace WondersAPI.Data
|
||||
{
|
||||
public class AppDbContext : DbContext
|
||||
{
|
||||
public DbSet<Wonder> Wonders => Set<Wonder>();
|
||||
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
|
||||
}
|
||||
}
|
22
Data/DataSeedingApplication.cs
Normal file
22
Data/DataSeedingApplication.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Text.Json;
|
||||
using WondersAPI.Models;
|
||||
|
||||
namespace WondersAPI.Data
|
||||
{
|
||||
public static class DataSeedingApplication
|
||||
{
|
||||
public static List<Wonder> SeedWonders(string filePath)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
throw new FileNotFoundException($"Seed data file not found: {filePath}");
|
||||
|
||||
var json = File.ReadAllText(filePath);
|
||||
var wonders = JsonSerializer.Deserialize<List<Wonder>>(json, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
|
||||
return wonders ?? new List<Wonder>();
|
||||
}
|
||||
}
|
||||
}
|
المرجع في مشكلة جديدة
حظر مستخدم