This commit is contained in:
2023-06-17 14:16:09 +03:00
parent 62178f1f32
commit 7ae5d3bc81
180 changed files with 12932 additions and 192 deletions
+26 -1
View File
@@ -1,5 +1,6 @@
namespace MyOffice.DbContext;
using Data.Models.Currencies;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
@@ -17,10 +18,34 @@ public class RepositoryInitializer
var db = AppDbContextFactory.Instance.CreateDbContext();
db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
//db.Database.EnsureCreated();
db.Database.Migrate();
Prefill(db);
}
public static ConnectionConfiguration ConnectionString { get; internal set; } = null!;
public static IServiceCollection Services { get; internal set; } = null!;
private static void Prefill(AppDbContext dbContext)
{
// CurrencyGlobals
var predefinedCurrencyGlobals = new List<CurrencyGlobal>()
{
new() { Id = "UAH", DefaultQuantity = 1, Symbol = "₴", Name = "Ukrainian hryvnias" },
new() { Id = "USD", DefaultQuantity = 1, Symbol = "$", Name = "US Dollar" },
new() { Id = "EUR", DefaultQuantity = 1, Symbol = "€", Name = "Euros" },
new() { Id = "GBP", DefaultQuantity = 1, Symbol = "£", Name = "British pounds sterling" },
new() { Id = "RUB", DefaultQuantity = 10, Symbol = "₽", Name = "Russia Ruble" },
};
var currencyGlobals = dbContext.CurrencyGlobals.ToList();
foreach (var predefined in predefinedCurrencyGlobals)
{
if (currencyGlobals.FirstOrDefault(x => x.Id == predefined.Id) == null)
{
dbContext.CurrencyGlobals.Add(predefined);
}
}
dbContext.SaveChanges();
}
}