mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Code refactor.
This commit is contained in:
@@ -38,8 +38,7 @@ namespace Marechai.Database.Models
|
||||
public class MarechaiContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
|
||||
{
|
||||
readonly ValueConverter<string, byte[]> hexToBytesConverter =
|
||||
new ValueConverter<string, byte[]>(v => HexStringToBytesConverter.StringToHex(v),
|
||||
v => HexStringToBytesConverter.HexToString(v));
|
||||
new(v => HexStringToBytesConverter.StringToHex(v), v => HexStringToBytesConverter.HexToString(v));
|
||||
|
||||
public MarechaiContext() {}
|
||||
|
||||
@@ -142,13 +141,17 @@ namespace Marechai.Database.Models
|
||||
|
||||
IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
|
||||
IConfigurationRoot configuration = builder.Build();
|
||||
optionsBuilder.UseMySql(configuration.GetConnectionString("DefaultConnection"), new MariaDbServerVersion(new Version(10, 5, 0)), b=> b.UseMicrosoftJson()).UseLazyLoadingProxies();
|
||||
|
||||
optionsBuilder.
|
||||
UseMySql(configuration.GetConnectionString("DefaultConnection"),
|
||||
new MariaDbServerVersion(new Version(10, 5, 0)), b => b.UseMicrosoftJson()).
|
||||
UseLazyLoadingProxies();
|
||||
}
|
||||
|
||||
public async Task<int> SaveChangesWithUserAsync(string userId)
|
||||
{
|
||||
ChangeTracker.DetectChanges();
|
||||
List<Audit> audits = new List<Audit>();
|
||||
List<Audit> audits = new();
|
||||
|
||||
foreach(EntityEntry entry in ChangeTracker.Entries())
|
||||
{
|
||||
@@ -161,10 +164,10 @@ namespace Marechai.Database.Models
|
||||
audit.UserId = userId;
|
||||
audit.Table = entry.Metadata.GetTableName();
|
||||
|
||||
Dictionary<string, object> keys = new Dictionary<string, object>();
|
||||
Dictionary<string, object> olds = new Dictionary<string, object>();
|
||||
Dictionary<string, object> news = new Dictionary<string, object>();
|
||||
List<string> columns = new List<string>();
|
||||
Dictionary<string, object> keys = new();
|
||||
Dictionary<string, object> olds = new();
|
||||
Dictionary<string, object> news = new();
|
||||
List<string> columns = new();
|
||||
|
||||
foreach(PropertyEntry property in entry.Properties)
|
||||
{
|
||||
|
||||
@@ -365,7 +365,7 @@ namespace Marechai.Database
|
||||
|
||||
Console.WriteLine("Getting all items from `console_company`");
|
||||
|
||||
Dictionary<int, string> consoleCompanies = new Dictionary<int, string>();
|
||||
Dictionary<int, string> consoleCompanies = new();
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = "SELECT * from console_company";
|
||||
@@ -376,7 +376,7 @@ namespace Marechai.Database
|
||||
foreach(DataRow dataRow in dataSet.Tables[0].Rows)
|
||||
consoleCompanies.Add(int.Parse(dataRow["id"].ToString()), dataRow["company"].ToString());
|
||||
|
||||
Dictionary<int, int> conversionEquivalents = new Dictionary<int, int>();
|
||||
Dictionary<int, int> conversionEquivalents = new();
|
||||
IDbTransaction trans;
|
||||
|
||||
Console.WriteLine("Converting all items from `console_company` to `companies`");
|
||||
@@ -417,7 +417,7 @@ namespace Marechai.Database
|
||||
}
|
||||
|
||||
Console.WriteLine("Getting all items from `consoles`");
|
||||
Dictionary<int, int> consoleIdAndCompanyId = new Dictionary<int, int>();
|
||||
Dictionary<int, int> consoleIdAndCompanyId = new();
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = "SELECT id,company from consoles";
|
||||
@@ -1309,7 +1309,7 @@ namespace Marechai.Database
|
||||
|
||||
Console.WriteLine("Getting all items from `music_synths`");
|
||||
|
||||
Dictionary<int, string> musicSynths = new Dictionary<int, string>();
|
||||
Dictionary<int, string> musicSynths = new();
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = "SELECT * from music_synths";
|
||||
@@ -1320,7 +1320,7 @@ namespace Marechai.Database
|
||||
foreach(DataRow dataRow in dataSet.Tables[0].Rows)
|
||||
musicSynths.Add(int.Parse(dataRow["id"].ToString()), dataRow["name"].ToString());
|
||||
|
||||
Dictionary<int, int> conversionEquivalents = new Dictionary<int, int>();
|
||||
Dictionary<int, int> conversionEquivalents = new();
|
||||
|
||||
Console.WriteLine("Converting all items from `music_synths` to `sound_synths`");
|
||||
|
||||
@@ -1359,7 +1359,7 @@ namespace Marechai.Database
|
||||
}
|
||||
|
||||
Console.WriteLine("Getting all items from `consoles`");
|
||||
Dictionary<int, int> consoleIdAndMusicSynthId = new Dictionary<int, int>();
|
||||
Dictionary<int, int> consoleIdAndMusicSynthId = new();
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = "SELECT id,music_synth from consoles";
|
||||
@@ -1391,7 +1391,7 @@ namespace Marechai.Database
|
||||
trans.Commit();
|
||||
|
||||
Console.WriteLine("Getting all items from `computers`");
|
||||
Dictionary<int, int> computerIdAndMusicSynthId = new Dictionary<int, int>();
|
||||
Dictionary<int, int> computerIdAndMusicSynthId = new();
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = "SELECT id,music_synth from computers";
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Marechai.Database.Seeders
|
||||
public static void Seed(MarechaiContext context)
|
||||
{
|
||||
List<DocumentRole> existingRoles = context.DocumentRoles.ToList();
|
||||
List<DocumentRole> newDocumentRoles = new List<DocumentRole>();
|
||||
List<DocumentRole> newDocumentRoles = new();
|
||||
int updatedDocumentRolesCount = 0;
|
||||
|
||||
foreach(DocumentRole role in new[]
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace Marechai.Database.Seeders
|
||||
}
|
||||
|
||||
Dictionary<string, Models.Iso4217> existingCodes = context.Iso4217.ToDictionary(c => c.Code);
|
||||
Dictionary<string, Models.Iso4217> newCodes = new Dictionary<string, Models.Iso4217>();
|
||||
Dictionary<string, Models.Iso4217> newCodes = new();
|
||||
|
||||
long modified = 0;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Marechai.Database.Seeders
|
||||
IEnumerable<string> files = Directory.EnumerateFiles("iso639", "iso-639-3_*.tab");
|
||||
long modified = 0;
|
||||
|
||||
List<Models.Iso639> codes = new List<Models.Iso639>();
|
||||
List<Models.Iso639> codes = new();
|
||||
|
||||
foreach(string file in files)
|
||||
{
|
||||
@@ -121,7 +121,7 @@ namespace Marechai.Database.Seeders
|
||||
}
|
||||
|
||||
List<Models.Iso639> existingCodes = context.Iso639.ToList();
|
||||
List<Models.Iso639> newCodes = new List<Models.Iso639>();
|
||||
List<Models.Iso639> newCodes = new();
|
||||
|
||||
foreach(Models.Iso639 code in codes)
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Marechai.Database.Seeders
|
||||
public static void Seed(MarechaiContext context)
|
||||
{
|
||||
List<Models.License> existingLicenses = context.Licenses.ToList();
|
||||
List<Models.License> newLicenses = new List<Models.License>();
|
||||
List<Models.License> newLicenses = new();
|
||||
int updatedLicencesCount = 0;
|
||||
|
||||
foreach(Models.License license in new[]
|
||||
|
||||
Reference in New Issue
Block a user