Session data.
This commit is contained in:
@@ -93,7 +93,7 @@ namespace Sarand.BusinessMgr.Web.Control.App
|
||||
try
|
||||
{
|
||||
propertySet = new PropertySet();
|
||||
SbmGlobals.System = (SbmGlobals_Web.System = (System_Web = new SbmSystem_Web(propertySet)));
|
||||
SbmGlobals.System = (SbmGlobals_Web.System = (System_Web = new SbmSystem_Control(this, propertySet)));
|
||||
Configuration = configuration;
|
||||
}
|
||||
catch (Exception exc)
|
||||
@@ -193,19 +193,9 @@ namespace Sarand.BusinessMgr.Web.Control.App
|
||||
// Consoles.
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
public override SaSecurityConsole CreateSecurityConsole(ISbmUserOrganisationContext userContext)
|
||||
public static SbmEmailConsole_Control CreateEmailConsole_Control(SbmEmailConfig emailConfig)
|
||||
{
|
||||
return new SbmSecurityConsole_Web(userContext);
|
||||
}
|
||||
|
||||
public override SaReferenceDataConsole CreateReferenceDataConsole(ISbmUserOrganisationContext userContext)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override SbmEmailConsole CreateEmailConsole(ISbmUserOrganisationContext userContext)
|
||||
{
|
||||
return new SbmEmailConsole_Control(EmailConfig);
|
||||
return new SbmEmailConsole_Control(emailConfig);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
@@ -14,17 +14,18 @@ using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.App
|
||||
{
|
||||
//=======================================================================
|
||||
public class SbmSessionData_Control : SbmSessionData_Web
|
||||
public class SbmSessionData_Control : SbmSessionData_Web, ISbmSessionData_Control
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
[JsonConstructor]
|
||||
private SbmSessionData_Control(long sessionIdx, int itemIdx, SbmSessionContext sessionContext) :
|
||||
base(sessionIdx, itemIdx, sessionContext)
|
||||
private SbmSessionData_Control(long sessionIdx, SbmSessionContext sessionContext) :
|
||||
base(sessionIdx, sessionContext)
|
||||
{ }
|
||||
/// <summary>
|
||||
/// SessionData construction.
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.Consoles;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
||||
using Sarand.BusinessMgr.Web.Control.Consoles;
|
||||
using Sarand.Net.Standard.Base.CodeTypes;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Diary;
|
||||
using Sarand.Net.Standard.Base.Interfaces;
|
||||
using Sarand.Net.Standard.Base.ItemData;
|
||||
using Sarand.Net.Standard.Base.ItemDocs;
|
||||
using Sarand.Net.Standard.Base.ItemOptions;
|
||||
using Sarand.Net.Standard.Base.ReferenceData;
|
||||
using Sarand.Net.Standard.Base.Security;
|
||||
using Sarand.Net.Standard.Base.UpdateLog;
|
||||
using System;
|
||||
using static Sarand.BusinessMgr.Net.Core.Web.App.SbmAppConfig;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.App
|
||||
{
|
||||
//=======================================================================
|
||||
public class SbmSystem_Control : SbmSystem_Web
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmApplication_Control app_Control;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmSystem_Control(SbmApplication_Control app, PropertySet properties) : base(properties)
|
||||
{
|
||||
app_Control = app;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Consoles.
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
public override SbmSessionConsole CreateSessionConsole(ISbmUserOrganisationContext userContext)
|
||||
{
|
||||
return SbmSessionConsole.CreateConsole(userContext);
|
||||
}
|
||||
|
||||
public override SaDiaryConsole CreateDiaryConsole(ISbmUserOrganisationContext userContext)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override SaCodeTypeConsole CreateCodeTypeConsole(ISbmUserOrganisationContext userContext)
|
||||
{
|
||||
return new SbmCodeTypeConsole_Web(userContext);
|
||||
}
|
||||
|
||||
public override SaItemDataConsole CreateItemDataConsole(ISbmUserOrganisationContext userContext)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override SaItemDocConsole CreateItemDocConsole(ISbmUserOrganisationContext userContext)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override SaItemOptionConsole CreateItemOptionConsole(ISbmUserOrganisationContext userContext)
|
||||
{
|
||||
return new SbmItemOptionConsole_Web(userContext);
|
||||
}
|
||||
|
||||
public override SaInterfaceConsole CreateInterfaceConsole(ISbmUserOrganisationContext userContext)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override SaUpdateLogConsole CreateUpdateLogConsole(ISbmUserOrganisationContext userContext)
|
||||
{
|
||||
return new SbmUpdateLogConsole_Web(userContext);
|
||||
}
|
||||
|
||||
public override SaSecurityConsole CreateSecurityConsole(ISbmUserOrganisationContext userContext)
|
||||
{
|
||||
return new SbmSecurityConsole_Web(userContext);
|
||||
}
|
||||
|
||||
public override SaReferenceDataConsole CreateReferenceDataConsole(ISbmUserOrganisationContext userContext)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override SbmEmailConsole CreateEmailConsole(ISbmUserOrganisationContext userContext, SbmEmailConfig emailConfig)
|
||||
{
|
||||
return SbmApplication_Control.CreateEmailConsole_Control(emailConfig);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using System;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.App
|
||||
{
|
||||
//=======================================================================
|
||||
/// <summary>
|
||||
/// Wrapper class to allow access to core internals from Control application.
|
||||
/// </summary>
|
||||
public class SbmUserContext_Control : ISbmUserOrganisationContext
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
public SbmUserContext_Control(SbmSessionData_Control sessionData)
|
||||
{
|
||||
SessionData = sessionData;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
private SbmSessionData_Control SessionData { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Session Context - Identifies database connections etc.</summary>
|
||||
public SbmSessionContext SessionContext { get { return null; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// User properties.
|
||||
/// <summary>User Security Item Id.</summary>
|
||||
public SysId UserSecurityItemId { get { return null; } }
|
||||
/// <summary>User Affiliate Id.</summary>
|
||||
public SysId UserAffiliateId { get { return null; } }
|
||||
/// <summary>User display name.</summary>
|
||||
public String UserDisplayName { get { return SessionData.UserDisplayName; } }
|
||||
/// <summary>User email address.</summary>
|
||||
public String UserEmailAddress { get { return SessionData.UserEmailAddress; } }
|
||||
/// <summary>Does the context represent a valid user account.</summary>
|
||||
public bool ValidUser { get { return SessionData.ValidUser; } }
|
||||
/// <summary>Database update info - user session specific properties for database inserts/updates.</summary>
|
||||
public DbUpdateInfo DbUpdateInfo { get { return SessionData.DbUpdateInfo; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Security profile - what the user is allowed to do based on security roles and groups.</summary>
|
||||
public ISbmSecurityProfile_Core SecurityProfile_Core { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Organisation properties.
|
||||
|
||||
/// <summary>Organisation Affiliate Id.</summary>
|
||||
public SysId OrganisationAffiliateId { get; }
|
||||
|
||||
/// <summary>Organisation Affiliate Type.</summary>
|
||||
public Sbm.AffiliateType OrganisationAffiliateType { get; }
|
||||
|
||||
/// <summary>Organisation 'Internal' Association Id.</summary>
|
||||
public SysId OrganisationAssociationId { get; }
|
||||
|
||||
/// <summary>Organisation display name.</summary>
|
||||
public String OrganisationDisplayName { get; }
|
||||
|
||||
/// <summary>Organisation Interface context - to qualify interfaces belonging to the organisation.</summary>
|
||||
public String OrganisationInterfaceContext { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Organisation configuration.
|
||||
public String GetOrganisationOption(Sbm.OrganisationOption option, String context) { return ""; }
|
||||
public String GetOrganisationOption(String optionName, String context) { return ""; }
|
||||
public String GetOwnerOption_Value(Sbm.OrgOption_Value eCol) { return ""; }
|
||||
public String GetOwnerOption_Folder(Sbm.OrgOption_Folder eCol) { return ""; }
|
||||
public bool GetOwnerOption_AllowOption(Sbm.OrgOption_AllowOption eCol) { return false; }
|
||||
public String GetOwnerOption_Caption(Sbm.OrgOption_Caption eCol, String defaultValue) { return ""; }
|
||||
public bool GetOwnerOption_ShowField(SbmDbDfn.ColumnIdx eCol) { return false; }
|
||||
public bool GetOwnerOption_ShowColumn(Sbm.OrgOption_ShowColumn eCol) { return false; }
|
||||
public String GetOwnerOption_FieldLabel(SbmDbDfn.ColumnIdx eCol, String defautValue) { return ""; }
|
||||
public int GetOwnerOption_Minutes(Sbm.OrgOption_Minutes eLimit, int defautValue) { return 0; }
|
||||
public int GetOwnerOption_UpdateLimit(Sbm.OrgOption_PeriodDays eLimit, int defautValue) { return 0; }
|
||||
public int GetOwnerOption_UpdateLimit(Sbm.OrgOption_PeriodWeeks eLimit, int defautValue) { return 0; }
|
||||
public int GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals eNumDecimals, int defautValue = 2) { return 2; }
|
||||
public Sbm.CommodityType GetOwnerOption_CommodityType(Sbm.OrgOption_CommodityType commodityTypeContext) { return Sbm.CommodityType.Unknown; }
|
||||
public SysId GetOwnerOption_StockLocation(Sbm.OrgOption_StockLocation eLoc) { return null; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
||||
using Sarand.BusinessMgr.Web.Control.App;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
@@ -25,16 +26,17 @@ namespace Sarand.BusinessMgr.Web.Control.Consoles
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SacsDatabase coreDatabase;
|
||||
private readonly SysId organisationId;
|
||||
private readonly SysId ownerId;
|
||||
private readonly SysId repositoryId;
|
||||
private SbmInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmCoreInstanceConsole_Control(SbmcRepository repository)
|
||||
public SbmCoreInstanceConsole_Control(SbmSessionData_Control sessionData_Control, SbmcRepository repository)
|
||||
{
|
||||
organisationId = repository.OwnerId;
|
||||
ownerId = repository.OwnerId;
|
||||
repositoryId = repository.Id;
|
||||
this.SessionData_Control = sessionData_Control;
|
||||
|
||||
// Repository connection.
|
||||
SacsDatabaseConsole.OdbcConfig config = GetRepositoryOdbcConfig(repository);
|
||||
@@ -52,7 +54,8 @@ namespace Sarand.BusinessMgr.Web.Control.Consoles
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public SbmApplication_Control App { get { return SbmApplication_Control.Instance; } }
|
||||
public static SbmApplication_Control App_Control { get { return SbmApplication_Control.Instance; } }
|
||||
public SbmSessionData_Control SessionData_Control { get; }
|
||||
public override ISacsDatabase Database_Core { get { return coreDatabase; } }
|
||||
public override SbmInternals Internals_Core { get { if (internals == null) { internals = CreateCoreInternals(); } return internals; } }
|
||||
public override DbUpdateInfo DbUpdateInfo_Core { get { return Internals_Core.DbUpdateInfo; } }
|
||||
@@ -70,24 +73,13 @@ namespace Sarand.BusinessMgr.Web.Control.Consoles
|
||||
}
|
||||
|
||||
/// <summary>Core internals for accessing core managers etc.</summary>
|
||||
public SbmInternals CreateCoreInternals()
|
||||
protected SbmInternals CreateCoreInternals()
|
||||
{
|
||||
ushort sessionIndex = App.GetCoreSessionIndexForControlRepository(organisationId, repositoryId);
|
||||
SbmSessionContext sessionContext = new SbmSessionContext_Web(sessionIndex, Sbm.Application.WebControl);
|
||||
SbmUserContext userContext = new SbmUserContext_Web(sessionContext);
|
||||
return new SbmInternals(userContext);
|
||||
ushort sessionIndex = App_Control.GetCoreSessionIndexForControlRepository(ownerId, repositoryId);
|
||||
SbmSessionContext sessionContext = App_Control.GetSessionContextByIndex(sessionIndex);
|
||||
return new SbmInternals(sessionContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create core security console.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override SaSecurityConsole CreateSecurityConsole()
|
||||
{
|
||||
return App.CreateSecurityConsole(internals.UserContext);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
}
|
||||
|
||||
// Repository Console.
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_Control(repository);
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_Control(SessionData_Control, repository);
|
||||
disposables.Add(instanceConsole);
|
||||
|
||||
// Columns.
|
||||
|
||||
+3
-2
@@ -233,7 +233,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
RefreshModel(model);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposables = new DisposableCollection<SacsHierarchyItem>())
|
||||
using (DisposableCollection<SacsDisposable> disposables = new DisposableCollection<SacsDisposable>())
|
||||
{
|
||||
|
||||
// Identify item.
|
||||
@@ -252,7 +252,8 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
responseData.repository.Id = SysId.ToString(repository.Id);
|
||||
|
||||
// Repository console.
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_Control(repository);
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_Control(SessionData_Control, repository);
|
||||
disposables.Add(instanceConsole);
|
||||
if (!instanceConsole.HasErrorState())
|
||||
{
|
||||
// Validate database.
|
||||
|
||||
+160
-21
@@ -128,27 +128,19 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
responseData.Repository.OwnerId = $"{SysId.ToLong(owner.Id)}";
|
||||
responseData.Repository.OwnerName = owner.Name;
|
||||
|
||||
// Repository Console.
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_Control(repository);
|
||||
// Core Instance Console.
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_Control(SessionData_Control, repository);
|
||||
disposables.Add(instanceConsole);
|
||||
|
||||
// Core internals.
|
||||
SbmInternals internals = instanceConsole.CreateCoreInternals();
|
||||
disposables.Add(internals);
|
||||
|
||||
// Core security console.
|
||||
SaSecurityConsole securityConsole = App.CreateSecurityConsole(internals.UserContext);
|
||||
disposables.Add(securityConsole);
|
||||
|
||||
// Query Organisations.
|
||||
SbmAssociation.Params prm = new SbmAssociation.Params();
|
||||
prm.AssociationType = Sbm.AssociationType.Internal;
|
||||
prm.StatusCat = SbmAssociation.StatusCat.Current;
|
||||
foreach (SbmAssociation association in internals.AccountMgr.GetAssociationList(prm))
|
||||
foreach (SbmAssociation association in instanceConsole.Internals_Core.AccountMgr.GetAssociationList(prm))
|
||||
{
|
||||
// Retrieve Organisation details.
|
||||
disposables.Add(association);
|
||||
SbmAffiliate affiliateOrganisation = internals.AccountMgr.GetAffiliateById(association.AffiliateIdOwner);
|
||||
SbmAffiliate affiliateOrganisation = instanceConsole.Internals_Core.AccountMgr.GetAffiliateById(association.AffiliateIdOwner);
|
||||
disposables.Add(affiliateOrganisation);
|
||||
|
||||
// Organisation details.
|
||||
@@ -167,27 +159,30 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
prmAffiliateUser.AffiliateIdAssocOwner = affiliateOrganisation.Id;
|
||||
prmAffiliateUser.AssociationType = Sbm.AssociationType.Member;
|
||||
prmAffiliateUser.StatusCat = SbmAffiliate.StatusCat.CurrentOnly;
|
||||
foreach (SbmAffiliate affiliateUser in internals.AccountMgr.GetAffiliateList(prmAffiliateUser))
|
||||
prmAffiliateUser.SortColumns.Add(instanceConsole.Internals_Core.AccountMgr.GetAffiliateColumnDfn(SbmAffiliate.Column.Id));
|
||||
foreach (SbmAffiliate affiliateUser in instanceConsole.Internals_Core.AccountMgr.GetAffiliateList(prmAffiliateUser))
|
||||
{
|
||||
disposables.Add(affiliateUser);
|
||||
|
||||
// Lookup security details.
|
||||
if (!SysId.IsValid(affiliateUser.UserId)) continue;
|
||||
SaSecurityItem securityUser = securityConsole.GetSecurityItemById(SaSecurity.ItemType.User, affiliateUser.UserId);
|
||||
disposables.Add(securityUser);
|
||||
if (securityUser == null) continue;
|
||||
SaSecurityItem securityItemUser = instanceConsole.Internals_Core.SecurityConsole.GetSecurityItemById(SaSecurity.ItemType.User, affiliateUser.UserId);
|
||||
disposables.Add(securityItemUser);
|
||||
if (securityItemUser == null) continue;
|
||||
|
||||
// Confirm security rights (SuperUser).
|
||||
SaSecurityProfile securityProfile = securityConsole.GetUserSecurityProfile(securityUser.Id);
|
||||
if (!securityProfile.Rights.Any(right => right.Code.EqualsCI(SaSecurityConsole.GroupCode_Super))) continue;
|
||||
SaSecurityProfile securityProfile = instanceConsole.Internals_Core.SecurityConsole.GetUserSecurityProfile(securityItemUser.Id);
|
||||
if (!securityProfile.Groups.Any(group => group.Code.EqualsCI(SaSecurityConsole.GroupCode_Super))) continue;
|
||||
|
||||
// Add User to the Organisation.
|
||||
RepositoryUserData userData = new RepositoryUserData()
|
||||
{
|
||||
AffiliateId = SysId.ToString(affiliateUser.Id),
|
||||
SecurityItemId = SysId.ToString(securityItemUser.Id),
|
||||
FirstName = affiliateUser.FirstName,
|
||||
LastName = affiliateUser.LastName,
|
||||
Email = StringUtil.OnBlank(securityUser.EmailAddress, affiliateUser.Email),
|
||||
Code = securityUser.Code,
|
||||
Email = StringUtil.OnBlank(securityItemUser.EmailAddress, affiliateUser.Email),
|
||||
Code = securityItemUser.Code,
|
||||
};
|
||||
organisation.Users.Add(userData);
|
||||
}
|
||||
@@ -241,13 +236,156 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Core Instance Console.
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_Control(SessionData_Control, repository);
|
||||
disposables.Add(instanceConsole);
|
||||
|
||||
// Validate Existing Organisation properties.
|
||||
if (StringUtil.ToBool(model.Organisation.Exists))
|
||||
{
|
||||
// Validate existing Organisation Affiliate.
|
||||
SysId affiliateIdOrganisation = SysId.ToSysId(model.Organisation.AffiliateId);
|
||||
if (!SysId.IsValid(affiliateIdOrganisation))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Affiliate Id not specified for existing Organisation.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Validate Organisation Affiliate.
|
||||
SbmAffiliate affiliateOrganisation = instanceConsole.Internals_Core.AccountMgr.GetAffiliateById(affiliateIdOrganisation);
|
||||
disposables.Add(affiliateOrganisation);
|
||||
if (affiliateOrganisation == null)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Affiliate not found for existing Organisation. Id: {model.Organisation.AffiliateId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!affiliateOrganisation.IsOrganisation())
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Affiliate for existing Organisation is not an organisation. Id: {model.Organisation.AffiliateId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
|
||||
// Validate existing Organisation Internal Association.
|
||||
SysId associationIdInternal = SysId.ToSysId(model.Organisation.AssociationId);
|
||||
if (!SysId.IsValid(associationIdInternal))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Association Id not specified for existing Organisation.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Validate Internal Association.
|
||||
SbmAssociation associationOrganisation = instanceConsole.Internals_Core.AccountMgr.GetAssociationById(associationIdInternal);
|
||||
disposables.Add(associationOrganisation);
|
||||
if (associationOrganisation == null)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Association not found for existing Organisation. Id: {model.Organisation.AssociationId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!associationOrganisation.AffiliateIdOwner.Equals(affiliateIdOrganisation))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Association for existing Organisation does not match Owner Affiliate. Id: {model.Organisation.AssociationId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!associationOrganisation.AffiliateIdTarget.Equals(affiliateIdOrganisation))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Association for existing Organisation does not match Target Affiliate. Id: {model.Organisation.AssociationId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!associationOrganisation.IsInternal())
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Association for existing Organisation is not internal. Id: {model.Organisation.AssociationId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Organisation does not exist.
|
||||
if (!SysId.IsValid(SysId.ToSysId(model.Organisation.AffiliateId)))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Affiliate Id specified for new Organisation. Id: {model.Organisation.AffiliateId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!SysId.IsValid(SysId.ToSysId(model.Organisation.AssociationId)))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Association Id specified for new Organisation. Id: {model.Organisation.AssociationId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
}
|
||||
|
||||
// Validate Existing User properties.
|
||||
if (StringUtil.ToBool(model.User.Exists))
|
||||
{
|
||||
// Validate existing User Affiliate.
|
||||
SysId affiliateIdUser = SysId.ToSysId(model.User.AffiliateId);
|
||||
if (!SysId.IsValid(affiliateIdUser))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Affiliate Id not specified for existing User.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Validate User Affiliate.
|
||||
SbmAffiliate affiliateUser = instanceConsole.Internals_Core.AccountMgr.GetAffiliateById(affiliateIdUser);
|
||||
disposables.Add(affiliateUser);
|
||||
if (affiliateUser == null)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Affiliate not found for existing User. Id: {model.User.AffiliateId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!affiliateUser.IsIndividual())
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Affiliate for existing User is not an individual. Id: {model.User.AffiliateId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Validate existing User Security Item.
|
||||
SysId secItemIdUser = SysId.ToSysId(model.User.SecurityItemId);
|
||||
if (!SysId.IsValid(secItemIdUser))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Security Item Id not specified for existing User.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Validate User Security Item.
|
||||
SaSecurityItem securityItemUser = instanceConsole.Internals_Core.SecurityConsole.GetSecurityItemById(SaSecurity.ItemType.User, secItemIdUser);
|
||||
disposables.Add(securityItemUser);
|
||||
if (securityItemUser == null)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Security Item not found for existing User. Id: {model.User.SecurityItemId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!securityItemUser.Id.Equals(affiliateUser.UserId))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Security Item for existing User does not match User Id on Affilliate. Expected: {model.User.SecurityItemId}. Found: {affiliateUser.UserId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// User does not exist.
|
||||
if (!SysId.IsValid(SysId.ToSysId(model.User.AffiliateId)))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Affiliate Id specified for new User. Id: {model.User.AffiliateId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!SysId.IsValid(SysId.ToSysId(model.User.SecurityItemId)))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Security Item Id specified for new User. Id: {model.User.SecurityItemId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
}
|
||||
|
||||
// Validate item properties.
|
||||
model.ValidateRepositoryData(responseData, repository);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Repository Console.
|
||||
SbmCoreInstanceConsole_Control repositoryConsole = new SbmCoreInstanceConsole_Control(repository);
|
||||
SbmCoreInstanceConsole_Control repositoryConsole = new SbmCoreInstanceConsole_Control(SessionData_Control, repository);
|
||||
disposables.Add(repositoryConsole);
|
||||
|
||||
SbmCoreInstanceConsole_Base.RepositoryInitialisationData repoInitData = new SbmCoreInstanceConsole_Base.RepositoryInitialisationData();
|
||||
@@ -264,6 +402,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
repoInitData.User.SecurityItemId = SysId.ToSysId(model.User.SecurityItemId);
|
||||
repoInitData.User.Code = model.User.Code;
|
||||
repoInitData.User.Password = model.User.Password;
|
||||
repoInitData.User.PasswordSet = StringUtil.ToBool(model.User.PasswordSet);
|
||||
if (!repositoryConsole.InitialiseRepository(repoInitData))
|
||||
return Json(responseData.SetMessage(messageTitle, repositoryConsole.ErrorStateMessage));
|
||||
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Newtonsoft.Json;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Web.Control.App;
|
||||
using Sarand.BusinessMgr.Web.Control.Consoles;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.Controllers;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr.Control;
|
||||
using Sarand.BusinessMgr.Web.Control.App;
|
||||
using Sarand.BusinessMgr.Web.Control.Consoles;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Email;
|
||||
using Sarand.Net.Standard.Base.Helpers;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Web;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
||||
using static Sarand.BusinessMgr.Net.Standard.Base.App.Sbm.Config.Database;
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.Controllers
|
||||
{
|
||||
@@ -28,28 +26,55 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private SbmInternals_Control internals_Control;
|
||||
private SbmEmailConsole_Control emailConsole;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Protected construction.
|
||||
protected SbmController_Control(SbmLocaliser localiser, Microsoft.Extensions.Logging.ILogger<SbmController_Control> logger) : base(localiser)
|
||||
{
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (internals_Control != null) internals_Control.Dispose(); internals_Control = null;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public SbmInternals_Control Internals_Control { get { if (internals_Control == null) { internals_Control = new SbmInternals_Control(); } return internals_Control; } }
|
||||
protected SbmcAccountMgr ControlAccountMgr { get { return Internals_Control.ControlAccountMgr; } }
|
||||
protected SbmcInstanceMgr ControlInstanceMgr { get { return Internals_Control.ControlInstanceMgr; } }
|
||||
protected SbmcItemMgr ControlItemMgr { get { return Internals_Control.ControlItemMgr; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Session data.
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Control session data</summary>
|
||||
protected SbmApplication_Control App_Control { get { return SbmApplication_Control.Instance; } }
|
||||
protected SbmSessionData_Control SessionData_Control { get { return SessionData as SbmSessionData_Control; } }
|
||||
public override ISbmUserOrganisationContext UserContext_Core { get { return new SbmUserContext_Control(SessionData_Control); } }
|
||||
public override ISbmUserOrganisationContext UserContext_Core => throw new NotImplementedException();
|
||||
protected override SbmSessionData_Web DeserializeSessionData(String sessionDataJson)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<SbmSessionData_Control>(sessionDataJson, SbmSessionDataJsonSerializerSettings);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Globals.
|
||||
// Email console.
|
||||
//-------------------------------------------------------------------
|
||||
public SbmEmailConsole_Control EmailConsole_Control { get { return Internals.EmailConsole as SbmEmailConsole_Control; } }
|
||||
public SaEmailConfig EmailConfig { get { return App_Control.EmailConfig; } }
|
||||
public SbmEmailConsole_Control EmailConsole_Control
|
||||
{
|
||||
get
|
||||
{
|
||||
if (emailConsole == null)
|
||||
emailConsole = SbmApplication_Control.CreateEmailConsole_Control(App_Control.EmailConfig);
|
||||
return emailConsole;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// User Session.
|
||||
@@ -88,7 +113,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers
|
||||
userAccount.LastInvalidLoginAt = null;
|
||||
if (!ControlAccountMgr.UpdateUserAccount(userAccount, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Failed to update User Account for " + userAccount.EmailAddress + ": " + AccountMgr.ErrorStateMessage);
|
||||
SaLogger.Warn($"{SysUtil.Fn} Failed to update User Account for " + userAccount.EmailAddress + ": " + ControlAccountMgr.ErrorStateMessage);
|
||||
errorMessage = Localiser["security.msg.signin.invalid"];
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -370,7 +370,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers
|
||||
emailData.AddressesTo.Add(userAccount.EmailAddress);
|
||||
emailData.Subject = controller.Localiser["caption.request.password"];
|
||||
PopulateRequestPasswordEmailBody(controller, emailData, userAccount, onlineContext);
|
||||
return controller.EmailConsole.SendEmail(emailData);
|
||||
return controller.EmailConsole_Control.SendEmail(emailData);
|
||||
}
|
||||
private static void PopulateRequestPasswordEmailBody(SbmController_Control controller, SaEmailData emailData, SbmcUserAccount userAccount, bool onlineContext)
|
||||
{
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace Sarand.BusinessMgr.Web.Control.Models.Instance
|
||||
// Organisation.
|
||||
public class OrganisationData
|
||||
{
|
||||
public String Exists { get; set; }
|
||||
public String AffiliateId { get; set; }
|
||||
public String AssociationId { get; set; }
|
||||
public String Name { get; set; }
|
||||
@@ -81,6 +82,7 @@ namespace Sarand.BusinessMgr.Web.Control.Models.Instance
|
||||
// User.
|
||||
public class UserData
|
||||
{
|
||||
public String Exists { get; set; }
|
||||
public String AffiliateId { get; set; }
|
||||
public String SecurityItemId { get; set; }
|
||||
public String FirstName { get; set; }
|
||||
@@ -88,6 +90,7 @@ namespace Sarand.BusinessMgr.Web.Control.Models.Instance
|
||||
public String Email { get; set; }
|
||||
public String Code { get; set; }
|
||||
public String Password { get; set; }
|
||||
public String PasswordSet { get; set; }
|
||||
}
|
||||
public UserData User { get; } = new UserData();
|
||||
public SysId GetUserAffiliateId()
|
||||
@@ -119,17 +122,9 @@ namespace Sarand.BusinessMgr.Web.Control.Models.Instance
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// Repository Console.
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_Control(repository);
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_Control(SessionData_Control, repository);
|
||||
disposables.Add(instanceConsole);
|
||||
|
||||
// Core internals.
|
||||
SbmInternals internals = instanceConsole.CreateCoreInternals();
|
||||
disposables.Add(internals);
|
||||
|
||||
// Core security console.
|
||||
SaSecurityConsole securityConsole = ControlApp.CreateSecurityConsole(internals.UserContext);
|
||||
disposables.Add(securityConsole);
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// Organisation Name.
|
||||
if (Organisation.Name != null)
|
||||
@@ -143,7 +138,7 @@ namespace Sarand.BusinessMgr.Web.Control.Models.Instance
|
||||
else
|
||||
{
|
||||
// Check that organisation name is not already in use.
|
||||
if (internals.AccountMgr.OrganisationExistsByName(Organisation.Name, GetOrganisationAffiliateId()))
|
||||
if (instanceConsole.Internals_Core.AccountMgr.OrganisationExistsByName(Organisation.Name, GetOrganisationAffiliateId()))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.duplicate.value"]);
|
||||
}
|
||||
}
|
||||
@@ -221,7 +216,7 @@ namespace Sarand.BusinessMgr.Web.Control.Models.Instance
|
||||
else
|
||||
{
|
||||
// Ensure that user name is not already in use.
|
||||
SysId securityItemId = securityConsole.GetIdForItemCode(SaSecurity.ItemType.User, User.Code);
|
||||
SysId securityItemId = instanceConsole.Internals_Core.SecurityConsole.GetIdForItemCode(SaSecurity.ItemType.User, User.Code);
|
||||
if (SysId.IsValid(securityItemId) && !securityItemId.Equals(GetUserSecurityItemId()))
|
||||
{
|
||||
|
||||
@@ -230,7 +225,7 @@ namespace Sarand.BusinessMgr.Web.Control.Models.Instance
|
||||
}
|
||||
|
||||
// User Password.
|
||||
if (User.Password != null)
|
||||
if (User.Password != null && (StringUtil.ToBool(User.PasswordSet) || !StringUtil.ToBool(User.Exists)))
|
||||
{
|
||||
String controlName = GetControlName(Control.UserPassword);
|
||||
responseData.SetControlValue(controlName, User.Password);
|
||||
|
||||
@@ -23,9 +23,9 @@ namespace Sarand.BusinessMgr.Web.Control.Models
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
protected SbmApplication_Control ControlApp { get { return SbmApplication_Control.Instance; } }
|
||||
protected SbmApplication_Control App_Control { get { return SbmApplication_Control.Instance; } }
|
||||
public SbmSessionData_Control SessionData_Control { get { return SessionData as SbmSessionData_Control; } }
|
||||
public override ISbmUserOrganisationContext UserContext_Core { get { return new SbmUserContext_Control(SessionData_Control); } }
|
||||
public override ISbmUserOrganisationContext UserContext_Core => throw new NotImplementedException();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public IEnumerable<SelectListItem> GetInstanceContextsForSelect()
|
||||
|
||||
Reference in New Issue
Block a user