using BlueWest.Data; using BlueWest.WebApi.EF.Model; using BlueWest.EfMethods; using BlueWest.WebApi.Extensions; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; namespace BlueWest.WebApi.EF { /// /// Countries and Currencies /// [EfGenerator] public sealed class CountryDbContext : DbContext { #region Countries /// /// Countries Database Table /// [EfGetOneBy( nameof(Country.Id), typeof(CountryUnique))] [EfGetOne(typeof(CountryUnique))] [EfAddMethods( createType: typeof(CountryCreate), returnType: typeof(CountryUnique)) ] [EfUpdateMethods( updateType: typeof(CountryUpdate), returnType: typeof(CountryUnique), keyPropertyMemberName: nameof(Country.Id)) ] [EfGetMany(typeof(CountryUnique))] public DbSet Countries { get; set; } #endregion #region Currencies /// /// Currencies Database Table /// [EfAddMethods(typeof(CurrencyCreate), typeof(CurrencyUnique))] [EfUpdateMethods( updateType: typeof(CurrencyUpdate), returnType: typeof(CurrencyUnique), keyPropertyMemberName: nameof(Currency.Id)) ] [EfGetOneBy( nameof(Currency.Id), typeof(CurrencyUnique))] [EfGetOne( typeof(CurrencyUnique))] public DbSet Currencies { get; set; } #endregion #region Initialization /// /// App Configuration /// public IConfiguration Configuration; /// /// CountryDbContext Constructor. /// /// public CountryDbContext(DbContextOptions options) : base(options) { Database.EnsureCreated(); } /// /// On model creating. /// /// protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.ConfigureCurrentDbModel(); modelBuilder.AddCurrencyAndCountryData(); } #endregion } }