CodeLiturgy.Dashboard/BlueWest.Api/Context/Extensions/ModelBuilderCountryDbContex...

63 lines
1.8 KiB
C#
Raw Normal View History

2022-09-08 06:15:44 +03:00
using System.Collections.Generic;
using BlueWest.Data;
using Microsoft.EntityFrameworkCore;
namespace BlueWest.WebApi.Context.Extensions
{
2022-09-10 00:33:17 +03:00
/// <summary>
/// Code first model builder
/// </summary>
2022-09-08 06:15:44 +03:00
public static class ModelBuilderCountryDbContextExtensions
{ /// <summary>
/// Setup the database model
/// </summary>
/// <param name="modelBuilder"></param>
public static void AddCurrencyAndCountryData(this ModelBuilder modelBuilder)
{
var currencies = new List<Currency>();
var usaCountry = new Country();
usaCountry.Id = 1;
usaCountry.Code = 1;
usaCountry.Name = "United States";
usaCountry.Alpha2Code = "US";
usaCountry.StateName = "United States of America";
usaCountry.TLD = "us";
var germanyCountry = new Country();
germanyCountry.Id = 2;
germanyCountry.Code = 2;
germanyCountry.Name = "Germany";
germanyCountry.Alpha2Code = "DE";
germanyCountry.StateName = "Germany";
germanyCountry.TLD = "de";
var dolar = new Currency();
dolar.Id = 1;
dolar.Code = "USD";
dolar.Countries = new List<Country>();
dolar.Countries.Add(usaCountry);
dolar.Num = 1;
var euro = new Currency();
euro.Id = 2;
euro.Code = "EUR";
euro.Countries = new List<Country>();
euro.Countries.Add(germanyCountry);
euro.Num = 2;
modelBuilder
.Entity<Currency>()
.HasData(currencies.ToArray());
}
}
}