QuellCode/CentronERP war nur als Gitlink (Submodul-Referenz auf 79c1142) getrackt, ohne .gitmodules und ohne erreichbares Remote. Der Untersuchungsgegenstand der Versuchsreihe war damit nicht reproduzierbar gesichert: Ein Klon haette ein leeres Verzeichnis erhalten, und die Belege der 3.287 Anforderungen waeren nicht ueberpruefbar gewesen. Umstellung: - Historie nach c:\DEV\CentronERP_git_snapshot_79c1142 ausgelagert (vollstaendig lesbar, enthaelt 79c1142 und Vorgaenger 89ccfd6) - Gitlink aus dem Index entfernt - Dateiinhalt aufgenommen: 24.557 Dateien, rund 333 MB Die verschachtelte .gitignore der Codebasis gilt weiter, Build-Artefakte bleiben ausgeschlossen. Details in Versuche/Versuch_01/_Codebasis-Nachweis.md
184 lines
5.6 KiB
C#
184 lines
5.6 KiB
C#
using System.Text;
|
|
using Centron.BusinessLogic.Administration.Settings;
|
|
using Centron.Common.TextCoding;
|
|
using Centron.Data.Entities.Accounts;
|
|
using Centron.Data.Entities.Administration;
|
|
using Centron.Data.Entities.Administration.Logins;
|
|
using Centron.Data.Entities.Administration.Settings;
|
|
using Centron.Data.Entities.CustomerArea;
|
|
using Centron.Data.Entities.EmployeeArea;
|
|
using Centron.DAO.TemporaryEntities;
|
|
using Centron.Interfaces.Administration.Settings;
|
|
using NHibernate;
|
|
|
|
namespace Centron.Tests.BL.SetupUtils;
|
|
|
|
public static class DbSetupUtils
|
|
{
|
|
public static AppUser SaveAppUser(
|
|
ISession session,
|
|
string? name,
|
|
string? email,
|
|
int id,
|
|
string? subjectId = null,
|
|
bool isAccountDisabled = false,
|
|
DateTime? commencementDate = null,
|
|
DateTime? leavingDate = null,
|
|
int state = 1,
|
|
string? plainTextPassword = null,
|
|
DateTime? disabledFromDate = null,
|
|
DateTime? disabledToDate = null,
|
|
bool isEmployeeActive = true)
|
|
{
|
|
var employee = new EmployeeCompact
|
|
{
|
|
I3D = id,
|
|
Email = email,
|
|
CommencementDate = commencementDate,
|
|
LeavingDate = leavingDate,
|
|
State = state,
|
|
IsActive = isEmployeeActive
|
|
};
|
|
|
|
string? encodedPassword = null;
|
|
if(plainTextPassword is not null)
|
|
{
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|
encodedPassword = SHA1Decoder.GetDecodedSHA1String(plainTextPassword);
|
|
}
|
|
var appUser = new AppUser
|
|
{
|
|
Name = name,
|
|
I3D = id,
|
|
Employee = employee,
|
|
OpenIdConnectSubjectIdentifier = subjectId,
|
|
IsAccountDisabled = isAccountDisabled,
|
|
Password = encodedPassword,
|
|
AccountDisabledFromDate = disabledFromDate,
|
|
AccountDisabledToDate = disabledToDate
|
|
};
|
|
return SaveAppUser(session, appUser, employee, id);
|
|
}
|
|
|
|
public static AppUser SaveAppUser(ISession session, AppUser appUser, EmployeeCompact employee, int id)
|
|
{
|
|
session.Save(employee, id);
|
|
session.Save(appUser, id);
|
|
session.Flush();
|
|
return session.Get<AppUser>(id);
|
|
}
|
|
|
|
public static int SetupResponsibleEmployeeForWebaccounts(ISession session, EmployeeCompact responsibleEmployee)
|
|
{
|
|
// Get the AppUser associated with this employee
|
|
var appUser = session.Query<AppUser>()
|
|
.FirstOrDefault(u => u.Employee.I3D == responsibleEmployee.I3D);
|
|
|
|
if (appUser == null)
|
|
throw new InvalidOperationException($"No AppUser found for Employee I3D {responsibleEmployee.I3D}");
|
|
|
|
var id = (int)ApplicationSettingID.CentronSystemUser;
|
|
|
|
var setting = new ApplicationSetting
|
|
{
|
|
I3D = id,
|
|
ValueInt = appUser.I3D,
|
|
Description = "Centron System User for Webaccounts"
|
|
};
|
|
session.Save(setting);
|
|
session.Flush();
|
|
return appUser.I3D;
|
|
}
|
|
public static WebAccount SaveWebAccount(
|
|
ISession session,
|
|
string? name,
|
|
string? email,
|
|
int id,
|
|
string? plainTextPassword,
|
|
int status = 1)
|
|
{
|
|
var customer = new Customer
|
|
{
|
|
I3D = id,
|
|
};
|
|
// var address = new Address
|
|
// {
|
|
// I3D = id,
|
|
// CustomerI3D = customer.I3D,
|
|
// State = 1,
|
|
// };
|
|
// var contactPerson = new ContactPerson // Personen
|
|
// {
|
|
// I3D = id,
|
|
// Address = address,
|
|
// State = 1
|
|
// };
|
|
var account = new Account
|
|
{
|
|
I3D = id,
|
|
IsActive = true,
|
|
IsLocked = false
|
|
};
|
|
var accountAddress = new AccountAddress
|
|
{
|
|
I3D = id,
|
|
IsActive = true,
|
|
AccountI3D = account.I3D
|
|
};
|
|
var addressContact = new AccountAddressContact
|
|
{
|
|
I3D = id,
|
|
AccountAddressI3D = accountAddress.I3D,
|
|
IsActive = true
|
|
};
|
|
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|
var encodedPassword = SHA1Decoder.GetDecodedSHA1String(plainTextPassword);
|
|
var webAccount = new WebAccount
|
|
{
|
|
I3D = id,
|
|
Username = name,
|
|
Status = status,
|
|
CustomerI3D = customer.I3D,
|
|
// AddressContactI3D = contactPerson.I3D,
|
|
AccountAddressContactI3D = addressContact.I3D,
|
|
Password = encodedPassword,
|
|
};
|
|
|
|
session.Save(customer, id);
|
|
// session.Save(address, id);
|
|
// session.Save(contactPerson, id);
|
|
session.Save(account, id);
|
|
session.Save(accountAddress, id);
|
|
session.Save(addressContact, id);
|
|
session.Save(webAccount, id);
|
|
session.Flush();
|
|
return session.Get<WebAccount>(id);
|
|
}
|
|
|
|
public static ApplicationSetting SaveApplicationSetting(
|
|
ISession session,
|
|
ApplicationSettingID id,
|
|
int? valueInt = null,
|
|
string? valueText = null,
|
|
decimal? valueDecimal = null,
|
|
string? description = null)
|
|
{
|
|
var setting = session.Get<ApplicationSetting>((int)id);
|
|
if (setting == null)
|
|
{
|
|
setting = new ApplicationSetting
|
|
{
|
|
I3D = (int)id
|
|
};
|
|
}
|
|
setting.ValueInt = valueInt;
|
|
setting.ValueText = valueText;
|
|
setting.ValueDecimal = valueDecimal;
|
|
setting.Description = description ?? "";
|
|
|
|
session.SaveOrUpdate(setting);
|
|
session.Flush();
|
|
return setting;
|
|
}
|
|
} |