584 lines
21 KiB
C#
584 lines
21 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using TrafagSalesExporter.Data;
|
|
using TrafagSalesExporter.Models;
|
|
|
|
namespace TrafagSalesExporter.Services;
|
|
|
|
public class DatabaseSeedService : IDatabaseSeedService
|
|
{
|
|
public void SeedDefaults(AppDbContext db)
|
|
{
|
|
SeedIfEmpty(db);
|
|
EnsureRecommendedTransformationRules(db);
|
|
EnsureSourceSystemDefinitions(db);
|
|
EnsureCentralHanaServerRecords(db);
|
|
EnsureSpainManualExcelSite(db);
|
|
EnsureSapODataDachSite(db);
|
|
EnsureFinanceReferenceDefaults(db);
|
|
EnsureBudgetExchangeRateDefaults(db);
|
|
EnsureFinanceIntercompanyRuleDefaults(db);
|
|
}
|
|
|
|
private static void SeedIfEmpty(AppDbContext db)
|
|
{
|
|
if (db.Sites.Any() || db.HanaServers.Any() || db.SharePointConfigs.Any() || db.ExportSettings.Any())
|
|
return;
|
|
|
|
var serverBi1 = new HanaServer { SourceSystem = "BI1", Name = "BI1", Host = "travtrp0", Port = 30015, Username = "", Password = "" };
|
|
var serverSage = new HanaServer { SourceSystem = "SAGE", Name = "SAGE", Host = "20.197.20.60", Port = 30015, Username = "", Password = "" };
|
|
db.HanaServers.AddRange(serverBi1, serverSage);
|
|
db.SaveChanges();
|
|
|
|
db.Sites.AddRange(
|
|
new Site { HanaServerId = serverBi1.Id, Schema = "fr01_p", TSC = "TRFR", Land = "Frankreich", SourceSystem = "BI1", IsActive = true },
|
|
new Site { HanaServerId = serverBi1.Id, Schema = "it01_p", TSC = "TRIT", Land = "Italien", SourceSystem = "BI1", IsActive = true },
|
|
new Site { HanaServerId = serverBi1.Id, Schema = "us01_p", TSC = "TRUS", Land = "USA", SourceSystem = "BI1", IsActive = true },
|
|
new Site { HanaServerId = serverSage.Id, Schema = "TRAFAG_LIVE", TSC = "TRIN", Land = "Indien", SourceSystem = "SAGE", IsActive = true }
|
|
);
|
|
|
|
db.SharePointConfigs.Add(new SharePointConfig
|
|
{
|
|
SiteUrl = "https://trafagag.sharepoint.com/sites/WorldwideBIPlatform",
|
|
ExportFolder = "/Shared Documents/Exports/",
|
|
CentralExportFolder = "",
|
|
TenantId = "",
|
|
ClientId = "",
|
|
ClientSecret = ""
|
|
});
|
|
|
|
db.ExportSettings.Add(new ExportSettings
|
|
{
|
|
DateFilter = "2025-01-01",
|
|
TimerHour = 3,
|
|
TimerMinute = 0,
|
|
TimerEnabled = true,
|
|
DebugLoggingEnabled = false,
|
|
LocalSiteExportFolder = "",
|
|
LocalConsolidatedExportFolder = ""
|
|
});
|
|
|
|
db.SaveChanges();
|
|
}
|
|
|
|
private static void EnsureRecommendedTransformationRules(AppDbContext db)
|
|
{
|
|
var recommendedRules = new[]
|
|
{
|
|
new FieldTransformationRule
|
|
{
|
|
SourceSystem = "MANUAL_EXCEL",
|
|
SourceField = nameof(SalesRecord.SalesCurrency),
|
|
TargetField = nameof(SalesRecord.SalesCurrency),
|
|
TransformationType = "Replace",
|
|
RuleScope = "Value",
|
|
Argument = "$=>USD",
|
|
SortOrder = 100,
|
|
IsActive = true
|
|
},
|
|
new FieldTransformationRule
|
|
{
|
|
SourceSystem = "MANUAL_EXCEL",
|
|
SourceField = nameof(SalesRecord.StandardCostCurrency),
|
|
TargetField = nameof(SalesRecord.StandardCostCurrency),
|
|
TransformationType = "Replace",
|
|
RuleScope = "Value",
|
|
Argument = "$=>USD",
|
|
SortOrder = 110,
|
|
IsActive = true
|
|
}
|
|
};
|
|
|
|
var hasChanges = false;
|
|
|
|
foreach (var rule in recommendedRules)
|
|
{
|
|
var exists = db.FieldTransformationRules.Any(existing =>
|
|
existing.SourceSystem == rule.SourceSystem &&
|
|
existing.RuleScope == rule.RuleScope &&
|
|
existing.SourceField == rule.SourceField &&
|
|
existing.TargetField == rule.TargetField &&
|
|
existing.TransformationType == rule.TransformationType &&
|
|
existing.Argument == rule.Argument);
|
|
|
|
if (exists)
|
|
continue;
|
|
|
|
db.FieldTransformationRules.Add(rule);
|
|
hasChanges = true;
|
|
}
|
|
|
|
if (hasChanges)
|
|
db.SaveChanges();
|
|
}
|
|
|
|
private static void EnsureCentralHanaServerRecords(AppDbContext db)
|
|
{
|
|
var centralSystems = db.SourceSystemDefinitions
|
|
.AsNoTracking()
|
|
.Where(x => x.ConnectionKind == SourceSystemConnectionKinds.Hana)
|
|
.OrderBy(x => x.Code)
|
|
.Select(x => x.Code)
|
|
.ToList();
|
|
var changed = false;
|
|
|
|
foreach (var sourceSystem in centralSystems)
|
|
{
|
|
var existingCentral = db.HanaServers
|
|
.OrderBy(x => x.Id)
|
|
.FirstOrDefault(x => x.SourceSystem == sourceSystem);
|
|
|
|
if (existingCentral is not null)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(existingCentral.Name))
|
|
{
|
|
existingCentral.Name = sourceSystem;
|
|
changed = true;
|
|
}
|
|
|
|
continue;
|
|
}
|
|
|
|
var linkedServer = db.Sites
|
|
.Include(x => x.HanaServer)
|
|
.Where(x => x.SourceSystem == sourceSystem && x.HanaServerId != null && x.HanaServer != null)
|
|
.Select(x => x.HanaServer!)
|
|
.OrderBy(x => x.Id)
|
|
.FirstOrDefault();
|
|
|
|
if (linkedServer is not null)
|
|
{
|
|
linkedServer.SourceSystem = sourceSystem;
|
|
if (string.IsNullOrWhiteSpace(linkedServer.Name))
|
|
linkedServer.Name = sourceSystem;
|
|
changed = true;
|
|
continue;
|
|
}
|
|
|
|
db.HanaServers.Add(new HanaServer
|
|
{
|
|
SourceSystem = sourceSystem,
|
|
Name = sourceSystem,
|
|
Host = string.Empty,
|
|
Port = 30015,
|
|
Username = string.Empty,
|
|
Password = string.Empty,
|
|
DatabaseName = string.Empty,
|
|
AdditionalParams = string.Empty
|
|
});
|
|
changed = true;
|
|
}
|
|
|
|
if (changed)
|
|
db.SaveChanges();
|
|
}
|
|
|
|
private static void EnsureSourceSystemDefinitions(AppDbContext db)
|
|
{
|
|
var defaults = new[]
|
|
{
|
|
new SourceSystemDefinition { Code = "SAP", DisplayName = "SAP OData", ConnectionKind = SourceSystemConnectionKinds.SapGateway, IsActive = true },
|
|
new SourceSystemDefinition { Code = "SAP_HANA", DisplayName = "SAP HANA Tables/Views", ConnectionKind = SourceSystemConnectionKinds.Hana, IsActive = true },
|
|
new SourceSystemDefinition { Code = "BI1", DisplayName = "BI1", ConnectionKind = SourceSystemConnectionKinds.Hana, IsActive = true },
|
|
new SourceSystemDefinition { Code = "SAGE", DisplayName = "SAGE", ConnectionKind = SourceSystemConnectionKinds.Hana, IsActive = true },
|
|
new SourceSystemDefinition { Code = "MANUAL_EXCEL", DisplayName = "Manual Excel", ConnectionKind = SourceSystemConnectionKinds.ManualExcel, IsActive = true }
|
|
};
|
|
|
|
var existing = db.SourceSystemDefinitions.ToList();
|
|
var changed = false;
|
|
|
|
foreach (var item in defaults)
|
|
{
|
|
var current = existing.FirstOrDefault(x => x.Code == item.Code);
|
|
if (current is null)
|
|
{
|
|
db.SourceSystemDefinitions.Add(item);
|
|
existing.Add(item);
|
|
changed = true;
|
|
continue;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(current.DisplayName))
|
|
{
|
|
current.DisplayName = item.DisplayName;
|
|
changed = true;
|
|
}
|
|
else if ((current.Code == "SAP" && current.DisplayName == "SAP") ||
|
|
(current.Code == "SAP_HANA" && current.DisplayName == "SAP HANA"))
|
|
{
|
|
current.DisplayName = item.DisplayName;
|
|
changed = true;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(current.ConnectionKind))
|
|
{
|
|
current.ConnectionKind = item.ConnectionKind;
|
|
changed = true;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(current.CentralServiceUrl) &&
|
|
string.Equals(current.ConnectionKind, SourceSystemConnectionKinds.SapGateway, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
var sapSite = db.Sites
|
|
.Where(x => x.SourceSystem == current.Code && !string.IsNullOrWhiteSpace(x.SapServiceUrl))
|
|
.OrderBy(x => x.Id)
|
|
.FirstOrDefault();
|
|
|
|
if (sapSite is not null)
|
|
{
|
|
current.CentralServiceUrl = sapSite.SapServiceUrl;
|
|
changed = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (changed)
|
|
db.SaveChanges();
|
|
}
|
|
|
|
private static void EnsureSpainManualExcelSite(AppDbContext db)
|
|
{
|
|
if (db.Sites.Count() <= 1)
|
|
return;
|
|
|
|
var existing = db.Sites
|
|
.OrderBy(x => x.Id)
|
|
.FirstOrDefault(x =>
|
|
x.TSC == "TRSE" ||
|
|
x.TSC == "TRES" ||
|
|
x.Land == "Spanien" ||
|
|
x.Land == "Spain");
|
|
|
|
if (existing is not null)
|
|
{
|
|
var changed = false;
|
|
|
|
if (string.IsNullOrWhiteSpace(existing.TSC))
|
|
{
|
|
existing.TSC = "TRES";
|
|
changed = true;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(existing.Land))
|
|
{
|
|
existing.Land = "Spanien";
|
|
changed = true;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(existing.SourceSystem))
|
|
{
|
|
existing.SourceSystem = "MANUAL_EXCEL";
|
|
changed = true;
|
|
}
|
|
|
|
if (changed)
|
|
db.SaveChanges();
|
|
|
|
return;
|
|
}
|
|
|
|
db.Sites.Add(new Site
|
|
{
|
|
Schema = string.Empty,
|
|
TSC = "TRES",
|
|
Land = "Spanien",
|
|
SourceSystem = "MANUAL_EXCEL",
|
|
IsActive = false
|
|
});
|
|
db.SaveChanges();
|
|
}
|
|
|
|
private static void EnsureSapODataDachSite(AppDbContext db)
|
|
{
|
|
if (db.Sites.Count() <= 1)
|
|
return;
|
|
|
|
var existing = db.Sites
|
|
.OrderBy(x => x.Id)
|
|
.FirstOrDefault(x =>
|
|
x.TSC == "ZSCHWEIZ" ||
|
|
x.Land == "Schweiz/Oesterreich" ||
|
|
x.Land == "DACH");
|
|
|
|
if (existing is not null)
|
|
{
|
|
var changed = false;
|
|
|
|
if (string.IsNullOrWhiteSpace(existing.TSC))
|
|
{
|
|
existing.TSC = "ZSCHWEIZ";
|
|
changed = true;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(existing.Land))
|
|
{
|
|
existing.Land = "Schweiz/Oesterreich";
|
|
changed = true;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(existing.SourceSystem) ||
|
|
string.Equals(existing.SourceSystem, "SAP_HANA", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
existing.SourceSystem = "SAP";
|
|
changed = true;
|
|
}
|
|
|
|
if (changed)
|
|
db.SaveChanges();
|
|
|
|
EnsureSapODataDachMapping(db, existing.Id);
|
|
return;
|
|
}
|
|
|
|
var site = new Site
|
|
{
|
|
Schema = string.Empty,
|
|
TSC = "ZSCHWEIZ",
|
|
Land = "Schweiz/Oesterreich",
|
|
SourceSystem = "SAP",
|
|
IsActive = false
|
|
};
|
|
db.Sites.Add(site);
|
|
db.SaveChanges();
|
|
EnsureSapODataDachMapping(db, site.Id);
|
|
}
|
|
|
|
private static void EnsureSapODataDachMapping(AppDbContext db, int siteId)
|
|
{
|
|
var changed = false;
|
|
var source = db.SapSourceDefinitions
|
|
.OrderBy(x => x.Id)
|
|
.FirstOrDefault(x => x.SiteId == siteId && x.Alias == "Z");
|
|
|
|
if (source is null)
|
|
{
|
|
db.SapSourceDefinitions.Add(new SapSourceDefinition
|
|
{
|
|
SiteId = siteId,
|
|
Alias = "Z",
|
|
EntitySet = "ZSCHWEIZSet",
|
|
IsPrimary = true,
|
|
IsActive = true,
|
|
SortOrder = 0
|
|
});
|
|
changed = true;
|
|
}
|
|
else
|
|
{
|
|
if (source.EntitySet != "ZSCHWEIZSet")
|
|
{
|
|
source.EntitySet = "ZSCHWEIZSet";
|
|
changed = true;
|
|
}
|
|
|
|
if (!source.IsPrimary)
|
|
{
|
|
source.IsPrimary = true;
|
|
changed = true;
|
|
}
|
|
|
|
if (!source.IsActive)
|
|
{
|
|
source.IsActive = true;
|
|
changed = true;
|
|
}
|
|
|
|
if (source.SortOrder != 0)
|
|
{
|
|
source.SortOrder = 0;
|
|
changed = true;
|
|
}
|
|
}
|
|
|
|
var mappings = new (string Target, string Source, bool Required)[]
|
|
{
|
|
(nameof(SalesRecord.Tsc), "Z.TSC", true),
|
|
(nameof(SalesRecord.Land), "Z.LAND1", true),
|
|
(nameof(SalesRecord.DocumentEntry), "Z.VBELN", false),
|
|
(nameof(SalesRecord.InvoiceNumber), "Z.VBELN", true),
|
|
(nameof(SalesRecord.PositionOnInvoice), "Z.POSNR", true),
|
|
(nameof(SalesRecord.InvoiceDate), "Z.FKDAT", true),
|
|
(nameof(SalesRecord.Material), "Z.MATNR", false),
|
|
(nameof(SalesRecord.Name), "Z.ARKTX", false),
|
|
(nameof(SalesRecord.ProductGroup), "Z.PRODH", false),
|
|
(nameof(SalesRecord.Quantity), "Z.FKIMG", false),
|
|
(nameof(SalesRecord.CustomerNumber), "Z.KUNNR", false),
|
|
(nameof(SalesRecord.CustomerName), "Z.NAME1", false),
|
|
(nameof(SalesRecord.CustomerCountry), "Z.CUSTOMER_LAND", false),
|
|
(nameof(SalesRecord.StandardCost), "=0", false),
|
|
(nameof(SalesRecord.StandardCostCurrency), "Z.HWAER", false),
|
|
(nameof(SalesRecord.SalesPriceValue), "Z.NETWR_HC", true),
|
|
(nameof(SalesRecord.SalesCurrency), "Z.HWAER", true),
|
|
(nameof(SalesRecord.DocumentCurrency), "Z.WAERK", false),
|
|
(nameof(SalesRecord.DocumentTotalForeignCurrency), "Z.NETWR_DC", false),
|
|
(nameof(SalesRecord.DocumentTotalLocalCurrency), "Z.NETWR_HC", false),
|
|
(nameof(SalesRecord.VatSumForeignCurrency), "Z.TAX_DC", false),
|
|
(nameof(SalesRecord.VatSumLocalCurrency), "Z.TAX_HC", false),
|
|
(nameof(SalesRecord.DocumentRate), "Z.KURRF", false),
|
|
(nameof(SalesRecord.CompanyCurrency), "Z.HWAER", true),
|
|
(nameof(SalesRecord.DocumentType), "Z.FKART", false)
|
|
};
|
|
|
|
for (var i = 0; i < mappings.Length; i++)
|
|
{
|
|
var mapping = db.SapFieldMappings
|
|
.OrderBy(x => x.Id)
|
|
.FirstOrDefault(x => x.SiteId == siteId && x.TargetField == mappings[i].Target);
|
|
|
|
if (mapping is null)
|
|
{
|
|
db.SapFieldMappings.Add(new SapFieldMapping
|
|
{
|
|
SiteId = siteId,
|
|
TargetField = mappings[i].Target,
|
|
SourceExpression = mappings[i].Source,
|
|
IsRequired = mappings[i].Required,
|
|
IsActive = true,
|
|
SortOrder = i
|
|
});
|
|
changed = true;
|
|
continue;
|
|
}
|
|
|
|
if (mapping.SourceExpression != mappings[i].Source)
|
|
{
|
|
mapping.SourceExpression = mappings[i].Source;
|
|
changed = true;
|
|
}
|
|
|
|
if (mapping.IsRequired != mappings[i].Required)
|
|
{
|
|
mapping.IsRequired = mappings[i].Required;
|
|
changed = true;
|
|
}
|
|
|
|
if (!mapping.IsActive)
|
|
{
|
|
mapping.IsActive = true;
|
|
changed = true;
|
|
}
|
|
|
|
if (mapping.SortOrder != i)
|
|
{
|
|
mapping.SortOrder = i;
|
|
changed = true;
|
|
}
|
|
}
|
|
|
|
if (changed)
|
|
db.SaveChanges();
|
|
}
|
|
|
|
private static void EnsureFinanceReferenceDefaults(AppDbContext db)
|
|
{
|
|
var defaults = new[]
|
|
{
|
|
new FinanceReference { Key = "AT", Label = "Trafag AT", Year = 2025, LocalCurrencyValue = 3443863m },
|
|
new FinanceReference { Key = "CH", Label = "Trafag CH", Year = 2025 },
|
|
new FinanceReference { Key = "CN", Label = "Trafag CN", Year = 2025 },
|
|
new FinanceReference { Key = "CZ", Label = "Trafag CZ", Year = 2025, LocalCurrencyValue = 95458782m },
|
|
new FinanceReference { Key = "DE", Label = "Trafag DE", Year = 2025, LocalCurrencyValue = 3635923m },
|
|
new FinanceReference { Key = "ES", Label = "Trafag ES", Year = 2025, LocalCurrencyValue = 3102334m },
|
|
new FinanceReference { Key = "FR", Label = "Trafag FR", Year = 2025, LocalCurrencyValue = 1450582m, CheckValue = 1471218m },
|
|
new FinanceReference { Key = "GFS", Label = "Trafag GfS", Year = 2025, LocalCurrencyValue = 6495513m },
|
|
new FinanceReference { Key = "IN", Label = "Trafag IN", Year = 2025, LocalCurrencyValue = 747341702m, CheckValue = 750936591m },
|
|
new FinanceReference { Key = "IT", Label = "Trafag IT", Year = 2025, LocalCurrencyValue = 7669840m },
|
|
new FinanceReference { Key = "JP", Label = "Trafag JP", Year = 2025, LocalCurrencyValue = 187739814m },
|
|
new FinanceReference { Key = "MS", Label = "Trafag MS", Year = 2025, LocalCurrencyValue = 1850199m },
|
|
new FinanceReference { Key = "MSA", Label = "Trafag MSA", Year = 2025, LocalCurrencyValue = 1445258m },
|
|
new FinanceReference { Key = "PL", Label = "Trafag PL Poltraf", Year = 2025, LocalCurrencyValue = 11279297m },
|
|
new FinanceReference { Key = "RU", Label = "Trafag RU", Year = 2025 },
|
|
new FinanceReference { Key = "UK", Label = "Trafag UK", Year = 2025, LocalCurrencyValue = 3538972m, CheckValue = 3749865m },
|
|
new FinanceReference { Key = "US", Label = "Trafag US", Year = 2025, LocalCurrencyValue = 3896728m, CheckValue = 3749865m }
|
|
};
|
|
|
|
var existing = db.FinanceReferences.ToList();
|
|
var changed = false;
|
|
foreach (var item in defaults)
|
|
{
|
|
var current = existing.FirstOrDefault(x => x.Year == item.Year && x.Key == item.Key);
|
|
if (current is not null)
|
|
continue;
|
|
|
|
db.FinanceReferences.Add(item);
|
|
changed = true;
|
|
}
|
|
|
|
if (changed)
|
|
db.SaveChanges();
|
|
}
|
|
|
|
private static void EnsureBudgetExchangeRateDefaults(AppDbContext db)
|
|
{
|
|
var defaults = new (string From, string To, decimal Rate)[]
|
|
{
|
|
("CHF", "CHF", 1m),
|
|
("USD", "CHF", 0.85m),
|
|
("EUR", "CHF", 0.95m),
|
|
("GBP", "CHF", 1.13m),
|
|
("CNY", "CHF", 1m / 8.50m),
|
|
("INR", "CHF", 1m / 90.91m),
|
|
("CZK", "CHF", 1m / 25.64m),
|
|
("PLN", "CHF", 0.22m),
|
|
("JPY", "CHF", 1m / 156.25m)
|
|
};
|
|
|
|
var changed = false;
|
|
foreach (var item in defaults)
|
|
{
|
|
var exists = db.CurrencyExchangeRates.Any(x =>
|
|
x.FromCurrency == item.From &&
|
|
x.ToCurrency == item.To &&
|
|
x.ValidFrom == new DateTime(2025, 1, 1) &&
|
|
x.Notes == "Budget 2025");
|
|
if (exists)
|
|
continue;
|
|
|
|
db.CurrencyExchangeRates.Add(new CurrencyExchangeRate
|
|
{
|
|
FromCurrency = item.From,
|
|
ToCurrency = item.To,
|
|
Rate = item.Rate,
|
|
ValidFrom = new DateTime(2025, 1, 1),
|
|
ValidTo = new DateTime(2025, 12, 31),
|
|
Notes = "Budget 2025",
|
|
IsActive = true
|
|
});
|
|
changed = true;
|
|
}
|
|
|
|
if (changed)
|
|
db.SaveChanges();
|
|
}
|
|
|
|
private static void EnsureFinanceIntercompanyRuleDefaults(AppDbContext db)
|
|
{
|
|
var defaults = new[]
|
|
{
|
|
new FinanceIntercompanyRule { CustomerNameContains = "TRAFAG", Notes = "Default IC name marker" },
|
|
new FinanceIntercompanyRule { CustomerNameContains = "MAGNETIC SENSE", Notes = "Default IC name marker" },
|
|
new FinanceIntercompanyRule { CustomerNameContains = "MAGNETS SENSE", Notes = "Default IC name marker" },
|
|
new FinanceIntercompanyRule { CustomerNameContains = "GESELLSCHAFT FUER SENSORIK", Notes = "Default IC name marker" },
|
|
new FinanceIntercompanyRule { CustomerNameContains = "GESELLSCHAFT FUR SENSORIK", Notes = "Default IC name marker" },
|
|
new FinanceIntercompanyRule { ScopeKey = "IT", CustomerNumber = "C_IT01_0306794", Notes = "IT IC customer number" },
|
|
new FinanceIntercompanyRule { ScopeKey = "IT", CustomerNumber = "C_CH01_0302179", Notes = "IT IC customer number" }
|
|
};
|
|
|
|
var changed = false;
|
|
foreach (var item in defaults)
|
|
{
|
|
var exists = db.FinanceIntercompanyRules.Any(x =>
|
|
x.ScopeKey == item.ScopeKey &&
|
|
x.CustomerNumber == item.CustomerNumber &&
|
|
x.CustomerNameContains == item.CustomerNameContains);
|
|
if (exists)
|
|
continue;
|
|
|
|
db.FinanceIntercompanyRules.Add(item);
|
|
changed = true;
|
|
}
|
|
|
|
if (changed)
|
|
db.SaveChanges();
|
|
}
|
|
}
|