Control - Repository initialisation.
This commit is contained in:
+5
-5
@@ -14,8 +14,8 @@ using System.Linq;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.Controllers.Account
|
||||
{
|
||||
//=======================================================================
|
||||
partial class UserAccountController
|
||||
//=======================================================================
|
||||
partial class UserAccountController
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
@@ -185,7 +185,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Account
|
||||
{
|
||||
|
||||
// Identify item.
|
||||
SysId userAccountId = model.User.Id.ToSysId();
|
||||
SysId userAccountId = SysId.ToSysId(model.User.Id);
|
||||
if (!SysId.IsValid(userAccountId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
@@ -265,7 +265,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Account
|
||||
RefreshModel(model);
|
||||
|
||||
// Validate item Id.
|
||||
SysId userAccountId = model.User.Id.ToSysId();
|
||||
SysId userAccountId = SysId.ToSysId(model.User.Id);
|
||||
if (StringUtil.ToBool(model.User.Exists) && !SysId.IsValid(userAccountId))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} User Id not supplied for existing item.");
|
||||
@@ -366,7 +366,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Account
|
||||
{
|
||||
|
||||
// Retrieve user.
|
||||
SysId userAccountId = model.User.Id.ToSysId();
|
||||
SysId userAccountId = SysId.ToSysId(model.User.Id);
|
||||
SbmcUserAccount userAccount = ControlAccountMgr.GetUserAccountById(userAccountId);
|
||||
disposables.Add(userAccount);
|
||||
if (userAccount == null)
|
||||
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
using DocumentFormat.OpenXml.Drawing.Charts;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.BusinessMgr.Web.Control.Consoles;
|
||||
using Sarand.BusinessMgr.Web.Control.Models;
|
||||
using Sarand.BusinessMgr.Web.Control.Models.Instance;
|
||||
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.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
{
|
||||
//=======================================================================
|
||||
partial class CoreDatabaseController
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
// Core Database Table list data.
|
||||
private class TableListData : AjaxResponse_Data.ItemData_Base
|
||||
{
|
||||
public String SchemaName { get; set; }
|
||||
public String TableName { get; set; }
|
||||
public long? ColumnCount { get; set; }
|
||||
public long? IndexCount { get; set; }
|
||||
public long? RowCount { get; set; }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Core Database Table list ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_CoreDatabaseTableList : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_CoreDatabaseTableList(SbmModel_Control model) : base(model) { }
|
||||
// CoreDatabase list.
|
||||
public List<TableListData> Tables { get; } = new List<TableListData>();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("Instance/CoreDatabase/Ajax/GetTableList")]
|
||||
[Route("Instance/CoreDatabase/Ajax/GetTables")]
|
||||
public IActionResult Ajax_GetTableList(Model_CoreDatabase model)
|
||||
{
|
||||
String messageTitle = Localiser["label.database"];
|
||||
AjaxResponse_CoreDatabaseTableList responseData = new AjaxResponse_CoreDatabaseTableList(model);
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer) return Forbid();
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsDisposable> disposables = new DisposableCollection<SacsDisposable>())
|
||||
{
|
||||
|
||||
// Validate Repository.
|
||||
SessionData_Control.Profile.Filter.InstanceContext = model.Filter.Context;
|
||||
if (StringUtil.IsBlank(model.Filter.Context))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Instance Context not supplied.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
SbmcRepository repository = ControlInstanceMgr.GetRepositoryByContext(model.Filter.Context);
|
||||
disposables.Add(repository);
|
||||
if (repository == null)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Repository does not exist. Context: {model.Filter.Context}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Repository Console.
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_Control(repository);
|
||||
disposables.Add(instanceConsole);
|
||||
|
||||
// Columns.
|
||||
String colSchemaName = "SchemaName";
|
||||
String colTableName = "TableName";
|
||||
String colColumnCount = "ColumnCount";
|
||||
String colIndexCount = "IndexCount";
|
||||
String colRowCount = "RowCount";
|
||||
|
||||
// Table filter.
|
||||
List<String> filter = new List<string>();
|
||||
if (!StringUtil.IsBlank(model.Filter.Search))
|
||||
filter.Add($"tbl.name Like '%{DbQuery.FormatForLike(model.Filter.Search)}%'");
|
||||
if (!filter.Any()) filter.Add("1=1");
|
||||
|
||||
// Construction query.
|
||||
List<String> sql = new List<string>()
|
||||
{
|
||||
$"Select Top 2000",
|
||||
$"[{colSchemaName}]=sch.name, [{colTableName}]=tbl.name,",
|
||||
$"[{colColumnCount}]=(Select Count(*) From sys.columns col Where col.object_id=tbl.object_id),",
|
||||
$"[{colIndexCount}]=(Select Count(*) From sys.indexes idx Where idx.object_id=tbl.object_id),",
|
||||
$"[{colRowCount}]=(Select Sum(ptn.rows) From sys.partitions ptn Where ptn.object_id=tbl.object_id And ptn.index_id<2)",
|
||||
$"From sys.tables tbl",
|
||||
$"Left Join sys.schemas sch On sch.schema_id=tbl.schema_id",
|
||||
$"Where tbl.type='U' And {filter.Concat(" And ","(",")")}",
|
||||
$"Order By tbl.name, sch.name;"
|
||||
};
|
||||
|
||||
// Query items.
|
||||
using (DbResultSet resultSet = instanceConsole.Database_Core.ExecuteQuery(String.Join("\n", sql)))
|
||||
{
|
||||
while (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
|
||||
{
|
||||
NamedValue.Map values = resultSet.GetRecordValues();
|
||||
TableListData tableData = new TableListData()
|
||||
{
|
||||
SchemaName = values.GetString(colSchemaName),
|
||||
TableName = values.GetString(colTableName),
|
||||
ColumnCount = values.GetLong(colColumnCount),
|
||||
IndexCount = values.GetLong(colIndexCount),
|
||||
RowCount = values.GetLong(colRowCount),
|
||||
};
|
||||
responseData.Tables.Add(tableData);
|
||||
}
|
||||
}
|
||||
if (model.Paging.IsPaged)
|
||||
model.Paging.ItemCount = (ushort)responseData.Tables.Count;
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
responseData.SetPaging(model);
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Web.Control.Models.Instance;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
{
|
||||
//======================================================================
|
||||
public partial class CoreDatabaseController : SbmController_Control
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public CoreDatabaseController(SbmLocaliser localiser, ILogger<CoreDatabaseController> logger) :
|
||||
base(localiser, logger)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
[Route("Instance/CoreDatabase")]
|
||||
public IActionResult Index(Model_CoreDatabase model)
|
||||
{
|
||||
if (!ValidUserSession)
|
||||
AutoLoginUser();
|
||||
|
||||
// Redirect to sign-in if not signed-in.
|
||||
if (!ValidUserSession)
|
||||
{
|
||||
ClearKeepLoggedInCookie();
|
||||
return RedirectToAction("", "Security");
|
||||
}
|
||||
|
||||
// Refresh model.
|
||||
RefreshModel(model);
|
||||
model.Filter.Context = SessionData_Control.Profile.Filter.InstanceContext;
|
||||
|
||||
// Core Database view.
|
||||
return View("Views/Instance/CoreDatabase/Index.cshtml", model);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//======================================================================
|
||||
}
|
||||
@@ -169,7 +169,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
{
|
||||
|
||||
// Identify item.
|
||||
SysId ownerId = model.Owner.Id.ToSysId();
|
||||
SysId ownerId = SysId.ToSysId(model.Owner.Id);
|
||||
if (!SysId.IsValid(ownerId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
RefreshModel(model);
|
||||
|
||||
// Validate item Id.
|
||||
SysId ownerId = model.Owner.Id.ToSysId();
|
||||
SysId ownerId = SysId.ToSysId(model.Owner.Id);
|
||||
if (StringUtil.ToBool(model.Owner.Exists) && !SysId.IsValid(ownerId))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Owner Id not supplied for existing item.");
|
||||
|
||||
+81
-3
@@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.BusinessMgr.Web.Control.Consoles;
|
||||
using Sarand.BusinessMgr.Web.Control.Models;
|
||||
using Sarand.BusinessMgr.Web.Control.Models.Instance;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
@@ -7,6 +8,7 @@ using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Sarand.Net.Standard.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static Sarand.BusinessMgr.Net.Standard.Base.App.Sbm.Config.Security;
|
||||
@@ -168,7 +170,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
{
|
||||
|
||||
// Identify item.
|
||||
SysId repositoryId = model.Repository.Id.ToSysId();
|
||||
SysId repositoryId = SysId.ToSysId(model.Repository.Id);
|
||||
if (!SysId.IsValid(repositoryId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
@@ -197,6 +199,82 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Repository ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_RepositoryInfo : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_RepositoryInfo(SbmModel_Control model) : base(model) { }
|
||||
// Repository details.
|
||||
public class RepositoryInfoData : AjaxResponse_Data.ItemData_Base
|
||||
{
|
||||
public byte? Initialised { get; set; }
|
||||
/// <summary>Tooltip text if database uninitialised.</summary>
|
||||
public String Uninitialised { get; set; }
|
||||
/// <summary>Tooltip text if database unavailable.</summary>
|
||||
public String Unavailable { get; set; }
|
||||
}
|
||||
public RepositoryInfoData repository { get; } = new RepositoryInfoData();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("Instance/Repository/Ajax/GetItemInfo")]
|
||||
[Route("Instance/Repository/Ajax/GetRepositoryInfo")]
|
||||
[Route("Instance/Repository/Ajax/GetRepoInfo")]
|
||||
public IActionResult Ajax_GetRepositoryInfo(Model_Repository model)
|
||||
{
|
||||
String messageTitle = Localiser["label.repository"];
|
||||
AjaxResponse_RepositoryInfo responseData = new AjaxResponse_RepositoryInfo(model);
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer) return Forbid();
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposables = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Identify item.
|
||||
SysId repositoryId = SysId.ToSysId(model.Repository.Id);
|
||||
if (!SysId.IsValid(repositoryId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
// Retrieve item.
|
||||
SbmcRepository repository = ControlInstanceMgr.GetRepositoryById(repositoryId);
|
||||
disposables.Add(repository);
|
||||
if (repository == null)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Failed to retrieve repository for Id: '" + repositoryId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
responseData.repository.Id = SysId.ToString(repository.Id);
|
||||
|
||||
// Repository console.
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_Control(repository);
|
||||
if (!instanceConsole.HasErrorState())
|
||||
{
|
||||
// Validate database.
|
||||
if (instanceConsole.IsRepositoryValid())
|
||||
{
|
||||
// Check whether repository is initialised.
|
||||
if (instanceConsole.IsRepositoryInitialised())
|
||||
{
|
||||
responseData.repository.Initialised = 1;
|
||||
}
|
||||
else responseData.repository.Uninitialised = instanceConsole.ErrorStateMessage;
|
||||
}
|
||||
else responseData.repository.Unavailable = instanceConsole.ErrorStateMessage;
|
||||
}
|
||||
else responseData.repository.Unavailable = instanceConsole.ErrorStateMessage;
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Store Repository ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
@@ -214,7 +292,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
RefreshModel(model);
|
||||
|
||||
// Validate item Id.
|
||||
SysId repositoryId = model.Repository.Id.ToSysId();
|
||||
SysId repositoryId = SysId.ToSysId(model.Repository.Id);
|
||||
if (StringUtil.ToBool(model.Repository.Exists) && !SysId.IsValid(repositoryId))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Repository Id not supplied for existing item.");
|
||||
@@ -245,7 +323,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
}
|
||||
|
||||
// Owner.
|
||||
SysId ownerId = repository?.OwnerId ?? StringUtil.ToSysId(model.Repository.OwnerId);
|
||||
SysId ownerId = repository?.OwnerId ?? SysId.ToSysId(model.Repository.OwnerId);
|
||||
SbmcOwner owner = ControlInstanceMgr.GetOwnerById(ownerId);
|
||||
disposables.Add(owner);
|
||||
if (owner == null)
|
||||
|
||||
+279
@@ -0,0 +1,279 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
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.Bus;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||
using Sarand.BusinessMgr.Web.Control.Consoles;
|
||||
using Sarand.BusinessMgr.Web.Control.Models;
|
||||
using Sarand.BusinessMgr.Web.Control.Models.Instance;
|
||||
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;
|
||||
|
||||
namespace Sarand.BusinessMgr.Web.Control.Controllers.Instance
|
||||
{
|
||||
//=======================================================================
|
||||
public partial class RepositoryInitController : SbmController_Control
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
// Repository data.
|
||||
/// <summary>
|
||||
/// Repository initialisation data.
|
||||
/// <para>- May have multiple (internal) Organisations.</para>
|
||||
/// <para>- Each Organisation may have multiple 'Superuser' users.</para>
|
||||
/// </summary>
|
||||
public class RepositoryData
|
||||
{
|
||||
// Repository data.
|
||||
public String Id { get; set; }
|
||||
public String OwnerId { get; set; }
|
||||
public String OwnerName { get; set; }
|
||||
public String Context { get; set; }
|
||||
// Organisations.
|
||||
public List<RepositoryOrganisationData> Organisations { get; } = new List<RepositoryOrganisationData>();
|
||||
}
|
||||
public class RepositoryOrganisationData
|
||||
{
|
||||
// Organisation data.
|
||||
public String AffiliateId { get; set; }
|
||||
public String AssociationId { get; set; }
|
||||
public String Name { get; set; }
|
||||
public String Website { get; set; }
|
||||
public String CompanyNo { get; set; }
|
||||
public String VatReg { get; set; }
|
||||
// Registered users.
|
||||
public List<RepositoryUserData> Users { get; } = new List<RepositoryUserData>();
|
||||
}
|
||||
public class RepositoryUserData
|
||||
{
|
||||
public String AffiliateId { get; set; }
|
||||
public String SecurityItemId { get; set; }
|
||||
public String FirstName { get; set; }
|
||||
public String LastName { get; set; }
|
||||
public String Email { get; set; }
|
||||
public String Code { get; set; }
|
||||
public String Password { get; set; }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public RepositoryInitController(SbmLocaliser localiser, ILogger<RepositoryController> logger) :
|
||||
base(localiser, logger)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Repository Initialisation Info ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_RepositoryInitInfo : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_RepositoryInitInfo(SbmModel_Control model) : base(model) { }
|
||||
// Repository initialisation info.
|
||||
public RepositoryData Repository { get; } = new RepositoryData();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("Instance/Repository/Ajax/GetInitInfo")]
|
||||
public IActionResult Ajax_GetRepositoryInitInfo(Model_RepositoryInit model)
|
||||
{
|
||||
String messageTitle = Localiser["label.repository"];
|
||||
AjaxResponse_RepositoryInitInfo responseData = new AjaxResponse_RepositoryInitInfo(model);
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer) return Forbid();
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsDisposable> disposables = new DisposableCollection<SacsDisposable>())
|
||||
{
|
||||
|
||||
// Validate Repository.
|
||||
SysId repositoryId = SysId.ToSysId(model.Repository.Id);
|
||||
if (!SysId.IsValid(repositoryId))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Repository Id not supplied.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
SbmcRepository repository = ControlInstanceMgr.GetRepositoryById(repositoryId);
|
||||
disposables.Add(repository);
|
||||
if (repository == null)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Repository does not exist. Id: {repositoryId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
responseData.Repository.Id = $"{SysId.ToLong(repository.Id)}";
|
||||
responseData.Repository.Context = repository.Context;
|
||||
|
||||
// Owner.
|
||||
SbmcOwner owner = ControlInstanceMgr.GetOwnerById(repository.OwnerId);
|
||||
disposables.Add(owner);
|
||||
if (owner == null)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Owner does not exist. Id: {repository.OwnerId}.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
responseData.Repository.OwnerId = $"{SysId.ToLong(owner.Id)}";
|
||||
responseData.Repository.OwnerName = owner.Name;
|
||||
|
||||
// Repository Console.
|
||||
SbmCoreInstanceConsole_Control instanceConsole = new SbmCoreInstanceConsole_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))
|
||||
{
|
||||
// Retrieve Organisation details.
|
||||
disposables.Add(association);
|
||||
SbmAffiliate affiliateOrganisation = internals.AccountMgr.GetAffiliateById(association.AffiliateIdOwner);
|
||||
disposables.Add(affiliateOrganisation);
|
||||
|
||||
// Organisation details.
|
||||
RepositoryOrganisationData organisation = new RepositoryOrganisationData()
|
||||
{
|
||||
AssociationId = SysId.ToString(association.Id),
|
||||
AffiliateId = SysId.ToString(affiliateOrganisation.Id),
|
||||
Name = affiliateOrganisation.Name,
|
||||
Website = affiliateOrganisation.Website,
|
||||
CompanyNo = affiliateOrganisation.CompanyNo,
|
||||
VatReg = affiliateOrganisation.VatReg,
|
||||
};
|
||||
|
||||
// Retrieve user details.
|
||||
SbmAffiliate.Params prmAffiliateUser = new SbmAffiliate.Params();
|
||||
prmAffiliateUser.AffiliateIdAssocOwner = affiliateOrganisation.Id;
|
||||
prmAffiliateUser.AssociationType = Sbm.AssociationType.Member;
|
||||
prmAffiliateUser.StatusCat = SbmAffiliate.StatusCat.CurrentOnly;
|
||||
foreach (SbmAffiliate affiliateUser in internals.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;
|
||||
|
||||
// Confirm security rights (SuperUser).
|
||||
SaSecurityProfile securityProfile = securityConsole.GetUserSecurityProfile(securityUser.Id);
|
||||
if (!securityProfile.Rights.Any(right => right.Code.EqualsCI(SaSecurityConsole.GroupCode_Super))) continue;
|
||||
|
||||
// Add User to the Organisation.
|
||||
RepositoryUserData userData = new RepositoryUserData()
|
||||
{
|
||||
FirstName = affiliateUser.FirstName,
|
||||
LastName = affiliateUser.LastName,
|
||||
Email = StringUtil.OnBlank(securityUser.EmailAddress, affiliateUser.Email),
|
||||
Code = securityUser.Code,
|
||||
};
|
||||
organisation.Users.Add(userData);
|
||||
}
|
||||
|
||||
// Add this Organisation to the list.
|
||||
responseData.Repository.Organisations.Add(organisation);
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Initialise Repository ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_RepositoryInitialise : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_RepositoryInitialise(SbmModel_Control model) : base(model) { }
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("Instance/Repository/Ajax/Initialise")]
|
||||
public IActionResult Ajax_StoreRepository(Model_RepositoryInit model)
|
||||
{
|
||||
String messageTitle = Localiser["label.repository"];
|
||||
AjaxResponse_RepositoryInitialise responseData = new AjaxResponse_RepositoryInitialise(model);
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer) return Forbid();
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsDisposable> disposables = new DisposableCollection<SacsDisposable>())
|
||||
{
|
||||
|
||||
// Validate Repository.
|
||||
SysId repositoryId = SysId.ToSysId(model.Repository.Id);
|
||||
if (!SysId.IsValid(repositoryId))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Repository Id not supplied.");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
SbmcRepository repository = ControlInstanceMgr.GetRepositoryById(repositoryId);
|
||||
disposables.Add(repository);
|
||||
if (repository == null)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Repository does not exist. Id: {repositoryId}.");
|
||||
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);
|
||||
disposables.Add(repositoryConsole);
|
||||
|
||||
SbmCoreInstanceConsole_Base.RepositoryInitialisationData repoInitData = new SbmCoreInstanceConsole_Base.RepositoryInitialisationData();
|
||||
repoInitData.Organisation.AffiliateId = SysId.ToSysId(model.Organisation.AffiliateId);
|
||||
repoInitData.Organisation.AssociationId = SysId.ToSysId(model.Organisation.AssociationId);
|
||||
repoInitData.Organisation.Name = model.Organisation.Name;
|
||||
repoInitData.Organisation.VatReg = model.Organisation.VatReg;
|
||||
repoInitData.Organisation.CompanyNo = model.Organisation.CompanyNo;
|
||||
repoInitData.Organisation.Website = model.Organisation.Website;
|
||||
repoInitData.User.AffiliateId = SysId.ToSysId(model.User.AffiliateId);
|
||||
repoInitData.User.FirstName = model.User.FirstName;
|
||||
repoInitData.User.LastName = model.User.LastName;
|
||||
repoInitData.User.Email = model.User.Email;
|
||||
repoInitData.User.SecurityItemId = SysId.ToSysId(model.User.SecurityItemId);
|
||||
repoInitData.User.Code = model.User.Code;
|
||||
repoInitData.User.Password = model.User.Password;
|
||||
if (!repositoryConsole.InitialiseRepository(repoInitData))
|
||||
return Json(responseData.SetMessage(messageTitle, repositoryConsole.ErrorStateMessage));
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -200,7 +200,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Param
|
||||
|
||||
// Item filter.
|
||||
SbmcItemParam.Params prmParam = new SbmcItemParam.Params();
|
||||
ItemId itemId = new ItemId(StringUtil.ToShort(model.Filter.ItemType), StringUtil.ToSysId(model.Filter.ItemId));
|
||||
ItemId itemId = new ItemId(StringUtil.ToShort(model.Filter.ItemType), SysId.ToSysId(model.Filter.ItemId));
|
||||
if (ItemId.IsValid(itemId))
|
||||
prmParam.ItemIdsIncluded.Add(itemId);
|
||||
prmParam.Search = model.Filter.Search;
|
||||
@@ -284,7 +284,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Param
|
||||
{
|
||||
|
||||
// Identify item.
|
||||
SysId itemParamId = model.Param.Id.ToSysId();
|
||||
SysId itemParamId = SysId.ToSysId(model.Param.Id);
|
||||
if (!SysId.IsValid(itemParamId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
@@ -321,7 +321,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Param
|
||||
RefreshModel(model);
|
||||
|
||||
// Validate item Id.
|
||||
SysId itemParamId = model.Param.Id.ToSysId();
|
||||
SysId itemParamId = SysId.ToSysId(model.Param.Id);
|
||||
if (StringUtil.ToBool(model.Param.Exists) && !SysId.IsValid(itemParamId))
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Id not supplied for existing Item Param.");
|
||||
@@ -352,7 +352,7 @@ namespace Sarand.BusinessMgr.Web.Control.Controllers.Param
|
||||
}
|
||||
|
||||
// Contruct item id.
|
||||
ItemId itemId = new ItemId(StringUtil.ToShort(model.Param.ItemType), model.Param.ItemId.ToSysId());
|
||||
ItemId itemId = new ItemId(StringUtil.ToShort(model.Param.ItemType), SysId.ToSysId(model.Param.ItemId));
|
||||
|
||||
if (itemParam != null && !itemParam.ItemId.Equals(itemId))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user