2022-08-13 06:35:36 +03:00
|
|
|
using BlueWest.Data;
|
2022-08-22 00:14:50 +03:00
|
|
|
using BlueWest.WebApi.EF.Model;
|
2022-09-06 01:17:47 +03:00
|
|
|
using BlueWest.EfMethods;
|
2022-09-06 07:54:48 +03:00
|
|
|
using BlueWest.WebApi.Extensions;
|
2022-08-13 06:35:36 +03:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
2022-08-22 00:14:50 +03:00
|
|
|
namespace BlueWest.WebApi.EF
|
2022-08-13 06:35:36 +03:00
|
|
|
{
|
2022-08-20 05:47:32 +03:00
|
|
|
|
2022-08-13 20:15:43 +03:00
|
|
|
/// <summary>
|
2022-08-20 05:47:32 +03:00
|
|
|
/// Countries and Currencies
|
2022-08-13 20:15:43 +03:00
|
|
|
/// </summary>
|
2022-09-05 05:58:37 +03:00
|
|
|
[EfGenerator]
|
2022-08-22 02:51:45 +03:00
|
|
|
public sealed class CountryDbContext : DbContext
|
2022-08-13 06:35:36 +03:00
|
|
|
{
|
|
|
|
|
2022-09-06 00:42:45 +03:00
|
|
|
#region Countries
|
2022-08-22 02:51:45 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Countries Database Table
|
|
|
|
/// </summary>
|
2022-09-06 00:42:45 +03:00
|
|
|
|
2022-09-06 01:17:47 +03:00
|
|
|
[EfGetOneBy(
|
|
|
|
nameof(Country.Id),
|
|
|
|
typeof(CountryUnique))]
|
2022-09-06 00:42:45 +03:00
|
|
|
|
|
|
|
[EfGetOne(typeof(CountryUnique))]
|
|
|
|
|
2022-08-27 23:02:46 +03:00
|
|
|
[EfAddMethods(
|
2022-08-29 03:40:57 +03:00
|
|
|
createType: typeof(CountryCreate),
|
2022-08-27 23:02:46 +03:00
|
|
|
returnType: typeof(CountryUnique))
|
|
|
|
]
|
2022-08-29 03:40:57 +03:00
|
|
|
[EfUpdateMethods(
|
2022-08-27 23:02:46 +03:00
|
|
|
updateType: typeof(CountryUpdate),
|
|
|
|
returnType: typeof(CountryUnique),
|
2022-09-01 08:54:42 +03:00
|
|
|
keyPropertyMemberName: nameof(Country.Id))
|
2022-08-27 23:02:46 +03:00
|
|
|
]
|
2022-09-06 00:42:45 +03:00
|
|
|
|
|
|
|
[EfGetMany(typeof(CountryUnique))]
|
|
|
|
|
2022-09-01 08:54:42 +03:00
|
|
|
|
2022-08-20 05:47:32 +03:00
|
|
|
public DbSet<Country> Countries { get; set; }
|
2022-09-06 00:42:45 +03:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Currencies
|
|
|
|
|
2022-08-22 02:51:45 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Currencies Database Table
|
|
|
|
/// </summary>
|
2022-09-06 00:42:45 +03:00
|
|
|
|
2022-08-24 19:56:51 +03:00
|
|
|
[EfAddMethods(typeof(CurrencyCreate), typeof(CurrencyUnique))]
|
2022-08-27 23:02:46 +03:00
|
|
|
|
2022-08-29 03:40:57 +03:00
|
|
|
[EfUpdateMethods(
|
2022-08-27 23:02:46 +03:00
|
|
|
updateType: typeof(CurrencyUpdate),
|
|
|
|
returnType: typeof(CurrencyUnique),
|
2022-09-01 08:54:42 +03:00
|
|
|
keyPropertyMemberName: nameof(Currency.Id))
|
2022-08-27 23:02:46 +03:00
|
|
|
]
|
2022-09-06 00:42:45 +03:00
|
|
|
|
|
|
|
[EfGetOneBy(
|
|
|
|
nameof(Currency.Id),
|
|
|
|
typeof(CurrencyUnique))]
|
|
|
|
|
|
|
|
[EfGetOne(
|
|
|
|
typeof(CurrencyUnique))]
|
|
|
|
|
2022-08-20 05:47:32 +03:00
|
|
|
public DbSet<Currency> Currencies { get; set; }
|
2022-08-27 23:02:46 +03:00
|
|
|
|
2022-09-06 00:42:45 +03:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Initialization
|
2022-08-22 02:51:45 +03:00
|
|
|
/// <summary>
|
|
|
|
/// App Configuration
|
|
|
|
/// </summary>
|
2022-08-20 05:47:32 +03:00
|
|
|
public IConfiguration Configuration;
|
2022-08-13 06:35:36 +03:00
|
|
|
|
2022-09-06 00:42:45 +03:00
|
|
|
|
2022-08-20 05:47:32 +03:00
|
|
|
/// <summary>
|
2022-08-22 05:13:53 +03:00
|
|
|
/// CountryDbContext Constructor.
|
2022-08-20 05:47:32 +03:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="options"></param>
|
|
|
|
public CountryDbContext(DbContextOptions<CountryDbContext> options) : base(options)
|
|
|
|
{
|
|
|
|
Database.EnsureCreated();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2022-08-22 05:13:53 +03:00
|
|
|
/// On model creating.
|
2022-08-20 05:47:32 +03:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="modelBuilder"></param>
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
{
|
|
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.ConfigureCurrentDbModel();
|
2022-09-06 07:54:48 +03:00
|
|
|
modelBuilder.AddCurrencyAndCountryData();
|
2022-08-20 05:47:32 +03:00
|
|
|
}
|
2022-09-06 00:42:45 +03:00
|
|
|
#endregion
|
2022-08-22 00:14:50 +03:00
|
|
|
|
2022-09-06 00:42:45 +03:00
|
|
|
}
|
2022-08-20 05:47:32 +03:00
|
|
|
}
|