63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using BlueWest.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace BlueWest.WebApi.Context.Extensions
|
|
{
|
|
/// <summary>
|
|
/// Code first model builder
|
|
/// </summary>
|
|
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());
|
|
}
|
|
|
|
}
|
|
}
|
|
|