144 lines
4.7 KiB
C#
144 lines
4.7 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Data;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Dbas;
|
|
using Sarand.Net.Standard.Base.Security;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static Sarand.BusinessMgr.Net.Standard.Base.Core.ISbmDemoInstanceConsole;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Consoles
|
|
{
|
|
//=======================================================================
|
|
/// <summary>
|
|
/// Utilitiy functions relating to the Demo BusinessMgr database instance.
|
|
/// <para>For instance:</para>
|
|
/// <para>- Database initialisation.</para>
|
|
/// <para>- Populate example data.</para>
|
|
/// <para>- Populate Demo Account User.</para>
|
|
/// </summary>
|
|
public abstract class SbmDemoInstanceConsole : SaErrorStateItem, ISbmDemoInstanceConsole
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SbmDemoInstanceConsole()
|
|
{
|
|
}
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
protected abstract SbmInternals Internals { get; }
|
|
protected DbUpdateInfo DbUpdateInfo { get { return Internals?.DbUpdateInfo ?? new DbUpdateInfo(null, "", ""); } }
|
|
protected abstract SbmCoreInstanceConsole InstanceConsole { get; }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
|
|
/// <summary>
|
|
/// Security Group codes - as set up during initialisation.
|
|
/// </summary>
|
|
public String GetSecurityGroupCode(SecurityGroup group)
|
|
{
|
|
switch (group)
|
|
{
|
|
case SecurityGroup.Standard: return "Standard";
|
|
case SecurityGroup.Super: return SaSecurityConsole.GroupCode_Super;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Verify Repository.
|
|
|
|
/// <summary>
|
|
/// Is repository database valid.
|
|
/// <para>- Contains core tables (Affiliate, Association, Commodity etc).</para>
|
|
/// </summary>
|
|
public bool IsRepositoryValid()
|
|
{
|
|
ClearErrorState();
|
|
if (InstanceConsole == null)
|
|
return SetErrorState("InstanceConsole not available.");
|
|
if (!InstanceConsole.IsRepositoryValid())
|
|
return SetErrorState(InstanceConsole.ErrorStateMessage);
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Repository population data preparation.
|
|
|
|
/// <summary>
|
|
/// Prepare a suitable batch of data to populate the demo database.
|
|
/// </summary>
|
|
public abstract SbmRepositoryPopulationData PrepareDemoPopulationData();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Populate Repository.
|
|
|
|
/// <summary>
|
|
/// Populate repository.
|
|
/// <br/>- Initialise repository: Organisation contact, Internal association, Security item and 'Super' group, User contact, User member association.
|
|
/// <br/>- Demo specific security.
|
|
/// <br/>- Populate demo data, including Repository configuration.
|
|
/// </summary>
|
|
public abstract bool PopulateRepository(SbmRepositoryPopulationData data);
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Get Affiliate Owner Ids for Internal Associations.
|
|
/// </summary>
|
|
public HashSet<SysId> GetInternalAssociationAffiliateIdsOwner()
|
|
{
|
|
return Internals.AccountMgr.GetInternalAssociationAffiliateIdsOwner();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// User Accounts.
|
|
|
|
/// <summary>
|
|
/// Check whether User Account already exists, ie. Security Item with matching code/email.
|
|
/// </summary>
|
|
public bool UserAccountExists(SbmRepositoryPopulationData.UserAccount userAccount)
|
|
{
|
|
ClearErrorState();
|
|
return InstanceConsole.UserAccountExists(userAccount);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add User Account.
|
|
/// </summary>
|
|
public bool AddUserAccount(SbmRepositoryPopulationData.UserAccount userAccount)
|
|
{
|
|
ClearErrorState();
|
|
if (!InstanceConsole.AddUserAccount(userAccount))
|
|
return SetErrorState(InstanceConsole.ErrorStateMessage);
|
|
return OK;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|
|
; |