Asset Categories
This commit is contained in:
@@ -19,8 +19,4 @@
|
||||
<ProjectReference Include="..\SaBusMgrStandardDbas\SaBusMgrStandardDbas.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Web\Core\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr.Control;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
@@ -9,7 +10,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using static Sarand.BusinessMgr.Net.Standard.Base.App.Sbm;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
{
|
||||
@@ -111,7 +111,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
{
|
||||
// Affiliate types.
|
||||
Sbm.AffiliateType affiliateType = EnumUtil.ParseEnum(itemParam.Name, Sbm.AffiliateType.Unknown);
|
||||
if (affiliateType != AffiliateType.Unknown)
|
||||
if (affiliateType != Sbm.AffiliateType.Unknown)
|
||||
{
|
||||
if (StringUtil.ToBool(itemParam.Value))
|
||||
AffiliateTypes_Allowed.Add(affiliateType);
|
||||
@@ -124,7 +124,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
{
|
||||
// Association types.
|
||||
Sbm.AssociationType associationType = EnumUtil.ParseEnum(itemParam.Name, Sbm.AssociationType.Unknown);
|
||||
if (associationType != AssociationType.Unknown)
|
||||
if (associationType != Sbm.AssociationType.Unknown)
|
||||
{
|
||||
if (StringUtil.ToBool(itemParam.Value))
|
||||
AssociationTypes_Allowed.Add(associationType);
|
||||
@@ -137,7 +137,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
{
|
||||
// Transaction types.
|
||||
Sbm.TransactionType transactionType = EnumUtil.ParseEnum(itemParam.Name, Sbm.TransactionType.Unknown);
|
||||
if (transactionType != TransactionType.Unknown)
|
||||
if (transactionType != Sbm.TransactionType.Unknown)
|
||||
{
|
||||
if (StringUtil.ToBool(itemParam.Value))
|
||||
TransactionTypes_Allowed.Add(transactionType);
|
||||
@@ -169,10 +169,26 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
else if (itemParam.Context.EqualsCI(ParamContext_DefaultValue))
|
||||
{
|
||||
// Default Value.
|
||||
if (itemParam.Name.EqualsCI("CommodityType"))
|
||||
{
|
||||
Sbm.CommodityType commodityType = EnumUtil.ParseEnum(itemParam.Value, Sbm.CommodityType.Unknown);
|
||||
if (commodityType > 0)
|
||||
Defaults.CommodityType = commodityType;
|
||||
else SaLogger.Debug($"{SysUtil.Fn} Unrecognised Default Commodity Type: '{itemParam.Value}'. Context: {itemParam.Context}. Name: {itemParam.Name}.");
|
||||
}
|
||||
else SaLogger.Debug($"{SysUtil.Fn} Unrecognised Default Value. Context: {itemParam.Context}. Name: {itemParam.Name}.");
|
||||
}
|
||||
else if (itemParam.Context.EqualsCI(ParamContext_ColumnChangeLogged))
|
||||
{
|
||||
// Update Log.
|
||||
SbmDbDfn.ColumnIdx column = EnumUtil.ParseEnum(itemParam.Name, SbmDbDfn.ColumnIdx.Unknown);
|
||||
if (column != SbmDbDfn.ColumnIdx.Unknown)
|
||||
{
|
||||
if (StringUtil.ToBool(itemParam.Value))
|
||||
ColumnChangeLogged_Allowed.Add(column);
|
||||
else ColumnChangeLogged_Disallowed.Add(column);
|
||||
}
|
||||
else SaLogger.Debug($"{SysUtil.Fn} Unrecognised Change Log column. Context: {itemParam.Context}. Name: {itemParam.Name}.");
|
||||
}
|
||||
else SaLogger.Debug($"{SysUtil.Fn} Unrecognised option. Context: {itemParam.Context}. Name: {itemParam.Name}.");
|
||||
}
|
||||
@@ -192,6 +208,16 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
return defaultResponse;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Defaults.
|
||||
|
||||
private ISbmInstanceConfig.DefaultsData Defaults { get; } = new ISbmInstanceConfig.DefaultsData();
|
||||
|
||||
public override ISbmInstanceConfig.DefaultsData GetDefaults()
|
||||
{
|
||||
return Defaults;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Contacts.
|
||||
|
||||
@@ -230,16 +256,33 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
|
||||
private readonly HashSet<SaInterfaceCategory> InterfaceCategories_Allowed = new HashSet<SaInterfaceCategory>();
|
||||
private readonly HashSet<SaInterfaceCategory> InterfaceCategories_Disallowed = new HashSet<SaInterfaceCategory>();
|
||||
|
||||
/// <summary>
|
||||
/// Whether the Interface Category is allowed.
|
||||
/// </summary>
|
||||
public override bool AllowInterfaceCategory(SaInterfaceCategory interfaceCategory, bool defaultResponse)
|
||||
{
|
||||
if (InterfaceCategories_Allowed.Contains(interfaceCategory)) return false;
|
||||
if (InterfaceCategories_Disallowed.Contains(interfaceCategory)) return true;
|
||||
if (InterfaceCategories_Disallowed.Contains(interfaceCategory)) return false;
|
||||
if (InterfaceCategories_Allowed.Contains(interfaceCategory)) return true;
|
||||
return defaultResponse;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update Log.
|
||||
|
||||
private readonly HashSet<SbmDbDfn.ColumnIdx> ColumnChangeLogged_Allowed = new HashSet<SbmDbDfn.ColumnIdx>();
|
||||
private readonly HashSet<SbmDbDfn.ColumnIdx> ColumnChangeLogged_Disallowed = new HashSet<SbmDbDfn.ColumnIdx>();
|
||||
|
||||
/// <summary>
|
||||
/// Are changes to values in the specified database column recorded in the Change Log.
|
||||
/// </summary>
|
||||
public override bool IsColumnChangeLogged(SbmDbDfn.ColumnIdx column, bool defaultResponse)
|
||||
{
|
||||
if (ColumnChangeLogged_Disallowed.Any(item => item == column)) return false;
|
||||
if (ColumnChangeLogged_Allowed.Any(item => item == column)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using DocumentFormat.OpenXml.Drawing.Diagrams;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr.Control;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
@@ -49,6 +50,14 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
return defaultResponse;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Defaults.
|
||||
|
||||
public override ISbmInstanceConfig.DefaultsData GetDefaults()
|
||||
{
|
||||
return new ISbmInstanceConfig.DefaultsData();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Contacts.
|
||||
|
||||
@@ -81,6 +90,14 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
return defaultResponse;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update Log.
|
||||
|
||||
public override bool IsColumnChangeLogged(SbmDbDfn.ColumnIdx column, bool defaultResponse)
|
||||
{
|
||||
return defaultResponse;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
+2
-3
@@ -21,7 +21,7 @@ using Sarand.Net.Standard.Base.Security;
|
||||
using Sarand.Net.Standard.Base.UpdateLog;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Components
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SbmController_Base : SaController
|
||||
@@ -53,8 +53,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
public SbmLocaliser Localiser { get; }
|
||||
protected SbmApplication_Web App { get { return SbmGlobals_Web.Application; } }
|
||||
public App.SbmAppConfig AppConfig { get { return App.AppConfig; } }
|
||||
public abstract SbmSessionContext SessionContext { get; }
|
||||
public abstract ISbmUserOrganisationContext UserContext_Core { get; }
|
||||
protected abstract SbmSessionContext SessionContext { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Action execution events.
|
||||
+14
-15
@@ -8,7 +8,6 @@ using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Sacs.Web.Components;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.Models;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||
@@ -38,7 +37,7 @@ using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Components
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SbmController_Web : SbmController_Base
|
||||
@@ -65,7 +64,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public override SbmSessionContext SessionContext { get { return SessionData?.SessionContext ?? null; } }
|
||||
protected override SbmSessionContext SessionContext { get { return SessionData?.SessionContext ?? null; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Action execution events.
|
||||
@@ -95,7 +94,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
// Some actions (eg. score password) don't need to.
|
||||
if (StoreSessionData)
|
||||
{
|
||||
String sessionDataJson = JsonConvert.SerializeObject(SessionData, SbmController_Web.SessionDataJsonSerializerSettings);
|
||||
string sessionDataJson = JsonConvert.SerializeObject(SessionData, SessionDataJsonSerializerSettings);
|
||||
HttpContext.Session.Set(SessionStorage.SessionKey_SessionData, SessionStorage.sessionDataEncoding.GetBytes(sessionDataJson));
|
||||
}
|
||||
}
|
||||
@@ -122,8 +121,8 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
if (model == null) return;
|
||||
|
||||
// Session data.
|
||||
model.Controller = this;
|
||||
model.SessionData_Web = SessionData;
|
||||
model.SetController(this);
|
||||
model.SetSessionData(SessionData);
|
||||
|
||||
// Redirect locations.
|
||||
model.RedirectLocation.Base = GetRedirectLocation(RedirectLocation.WebAppBase);
|
||||
@@ -138,18 +137,18 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
// the base Controller so that they can be shared with the Admin application.
|
||||
// NB IV value is generated from the key and fixed so that it doesn't change when the application restarts.
|
||||
// IV Must be regenerated if key is changed.
|
||||
protected static String Base64Key_RequestPassword_Portal { get; } = SacsEncryptionHelper.EncodePlainKey("[5Abus1neSSmGR~Request#Password}", SacsEncryptionHelper.KeyLength);
|
||||
protected static string Base64Key_RequestPassword_Portal { get; } = SacsEncryptionHelper.EncodePlainKey("[5Abus1neSSmGR~Request#Password}", SacsEncryptionHelper.KeyLength);
|
||||
//private static String Base64IV_RequestPassword_Generated_Portal = SacsEncryptionHelper.InitSymmetricEncryptionIV(Base64Key_RequestPassword_Portal);
|
||||
protected static String Base64IV_RequestPassword_Portal { get; } = "8TRhBayBJZmACQ6pld1F9A==";
|
||||
protected static string Base64IV_RequestPassword_Portal { get; } = "8TRhBayBJZmACQ6pld1F9A==";
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Session.
|
||||
//-------------------------------------------------------------------
|
||||
public bool ValidUserSession { get { return SessionData?.ValidUser ?? false; } }
|
||||
public DbUpdateInfo DbUpdateInfo { get { return SessionData?.DbUpdateInfo ?? new DbUpdateInfo(null, "", SbmSystem.ComputerName); } }
|
||||
protected bool ValidUserSession { get { return SessionData?.ValidUser ?? false; } }
|
||||
protected DbUpdateInfo DbUpdateInfo { get { return SessionData?.DbUpdateInfo ?? new DbUpdateInfo(null, "", SacsSystem.ComputerName); } }
|
||||
// Referrer.
|
||||
public String Referer { get { return Request.Headers["Referer"].ToString(); } }
|
||||
public bool ValidReferer { get { return !StringUtil.IsEmpty(Referer); } }
|
||||
protected string Referer { get { return Request.Headers["Referer"].ToString(); } }
|
||||
protected bool ValidReferer { get { return !Referer.IsEmpty(); } }
|
||||
/// <summary>Store session data, eg. to start a new user session on sign-in.</summary>
|
||||
protected bool SetSessionData(SbmSessionData_Web sessionData)
|
||||
{
|
||||
@@ -169,7 +168,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
public class SessionStorage
|
||||
{
|
||||
public SbmSessionData_Web SessionData { get; set; }
|
||||
public static String SessionKey_SessionData { get; } = "SbmSessionData";
|
||||
public static string SessionKey_SessionData { get; } = "SbmSessionData";
|
||||
public static Encoding sessionDataEncoding { get; } = Encoding.UTF8;
|
||||
//JSON Serialisation.
|
||||
public class SbmSessionDataContractResolver : DefaultContractResolver
|
||||
@@ -219,7 +218,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
HttpContext.Session.TryGetValue(SessionStorage.SessionKey_SessionData, out sessionDataBytes);
|
||||
if (sessionDataBytes != null)
|
||||
{
|
||||
String sessionDataJson = SessionStorage.sessionDataEncoding.GetString(sessionDataBytes);
|
||||
string sessionDataJson = SessionStorage.sessionDataEncoding.GetString(sessionDataBytes);
|
||||
sessionStorage.SessionData = DeserializeSessionData(sessionDataJson);
|
||||
}
|
||||
}
|
||||
@@ -232,7 +231,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||
return null;
|
||||
}
|
||||
}
|
||||
protected abstract SbmSessionData_Web DeserializeSessionData(String sessionDataJson);
|
||||
protected abstract SbmSessionData_Web DeserializeSessionData(string sessionDataJson);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
using Microsoft.AspNetCore.Html;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Sacs.Web.Components;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr.Control;
|
||||
using Sarand.Net.Standard.Base.CodeTypes;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
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 Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Components
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SbmModel_Base : SaModel
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private SbmInternals_Control internals_Control;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Protected construction.
|
||||
protected SbmModel_Base(SbmLocaliser localiser)
|
||||
{
|
||||
Localiser = localiser;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (internals_Control != null) internals_Control.Dispose(); internals_Control = null;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Application properties.
|
||||
private SbmApplication_Web App { get { return SbmGlobals_Web.Application; } }
|
||||
protected App.SbmAppConfig AppConfig { get { return App.AppConfig; } }
|
||||
protected SbmSystem_Web System { get { return App.System_Web; } }
|
||||
public string SessionCookieName { get { return App.SessionCookieName; } }
|
||||
protected SbmSessionData_Web SessionData_Web { get; private set; }
|
||||
internal void SetSessionData(SbmSessionData_Web sessionData) { SessionData_Web = sessionData; }
|
||||
protected SbmSessionContext SessionContext { get { return SessionData_Web?.SessionContext ?? null; } }
|
||||
protected DbUpdateInfo DbUpdateInfo { get { return SessionData_Web?.DbUpdateInfo ?? new DbUpdateInfo(null, "", Sarand.Net.Standard.Base.App.SacsSystem.ComputerName); } }
|
||||
protected SbmLocaliser Localiser { get; }
|
||||
// Request properties.
|
||||
protected SbmController_Web Controller { get; private set; }
|
||||
internal void SetController(SbmController_Web controller) { Controller = controller; }
|
||||
protected CultureInfo SessionCulture { get { return Controller?.SessionCulture ?? CultureInfo.InvariantCulture; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Page configuration.
|
||||
public string InstanceVersion { get { return !App.AppConfig.Instance.IsEmpty() ? App.AppConfig.Instance + " v" + Sbm.Version.GetFullVersion() : "v" + Sbm.Version.GetAppVersion(); } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Business components.
|
||||
// NB Keep these accessors protected to avoid them being called by the model binding logic before the session data is ready.
|
||||
protected SbmInternals_Control Internals_Control { get { if (internals_Control == null) internals_Control = new SbmInternals_Control(); return internals_Control; } }
|
||||
// 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; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Security.
|
||||
protected bool ValidUserSession { get { return SessionData_Web?.ValidUser ?? false; } }
|
||||
public bool AwaitingLogin { get { return !ValidUserSession; } }
|
||||
public bool KeepLoggedIn { get { return !AwaitingLogin && (SessionData_Web?.KeepLoggedIn ?? false); } }
|
||||
/// <summary>Maximum length allowed for password entry: sign-up, change password etc.</summary>
|
||||
public int PasswordMaxLength { get; } = 32;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Form control value max length - Security tables.
|
||||
/// <para>In many cases the database columns allow plenty of extra space for the value, in case they need to be encrypted.</para>
|
||||
/// <para>Hence, several cases where the value entered in the control isn't allowed the full database length.</para>
|
||||
/// </summary>
|
||||
public int GetControlMaxLength(SaSecurityDbDfn.ColumnIdx column)
|
||||
{
|
||||
int maxLength = (int)SaSecurityDbDfn.GetColTextLen(column);
|
||||
switch (column)
|
||||
{
|
||||
case SaSecurityDbDfn.ColumnIdx.SaSecItem_EmailAddress:
|
||||
return Math.Min(maxLength, 100);
|
||||
}
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Form control value max length - code type tables.
|
||||
/// <para>In many cases the database columns allow plenty of extra space for the value, in case they need to be encrypted.</para>
|
||||
/// <para>Hence, several cases where the value entered in the control isn't allowed the full database length.</para>
|
||||
/// </summary>
|
||||
public int GetControlMaxLength(SaCodeTypeDbDfn.ColumnIdx column)
|
||||
{
|
||||
int maxLength = (int)SaCodeTypeDbDfn.GetColTextLen(column);
|
||||
switch (column)
|
||||
{
|
||||
case SaCodeTypeDbDfn.ColumnIdx.SaCodeType_Name:
|
||||
case SaCodeTypeDbDfn.ColumnIdx.SaCode_Description:
|
||||
return Math.Min(maxLength, 100);
|
||||
}
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Form control value max length - BusinessMgr tables.
|
||||
/// <para>In many cases the database columns allow plenty of extra space for the value, in case they need to be encrypted.</para>
|
||||
/// <para>Hence, several cases where the value entered in the control isn't allowed the full database length.</para>
|
||||
/// </summary>
|
||||
public int GetControlMaxLength(SbmDbDfn.ColumnIdx column)
|
||||
{
|
||||
int maxLength = (int)SbmDbDfn.GetColTextLen(column);
|
||||
switch (column)
|
||||
{
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_Email:
|
||||
return Math.Min(maxLength, 100);
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_FirstName:
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_LastName:
|
||||
return Math.Min(maxLength, 40);
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_Name:
|
||||
return Math.Min(maxLength, 80);
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_PhoneMain:
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_PhoneMobile:
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_PhoneAlt:
|
||||
return Math.Min(maxLength, 20);
|
||||
case SbmDbDfn.ColumnIdx.Address_Postcode:
|
||||
return Math.Min(maxLength, 16);
|
||||
}
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copyright notice.
|
||||
public HtmlString CopyrightNotice
|
||||
{
|
||||
get
|
||||
{
|
||||
int initialYear = 2020;
|
||||
int currentYear = DateTime.Today.Year;
|
||||
return Localiser.GetHtmlText("copyright.symbol.year.html", (initialYear != currentYear ? initialYear + "-" : "") + currentYear.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Display data - Dates.
|
||||
public string FormatDateForDisplay(DateTime? value)
|
||||
{
|
||||
return value.Format("d-MMM-yy", SessionCulture);
|
||||
}
|
||||
public string FormatDateTimeForDisplay(DateTime? value)
|
||||
{
|
||||
return value.Format("d-MMM-yy HH:mm", SessionCulture).TrimAll();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Form data - Dates.
|
||||
// Format may depend on locale, but as long as these methods are used consistently,
|
||||
// there should be consistent formatting, display and parsing of date values.
|
||||
public string CalendarDateFormat
|
||||
{
|
||||
get
|
||||
{
|
||||
// JQuery-UI DatePicker date format.
|
||||
// Format:
|
||||
// d Single digit day of month
|
||||
// dd Double digit day of month
|
||||
// D 3 letter day of week abbreviation.
|
||||
// DD Day of week.
|
||||
// m Single digit month.
|
||||
// mm Double digit month.
|
||||
// M 3 letter month abbreviation.
|
||||
// MM Month name.
|
||||
// yy 4 digit year.
|
||||
// Examples:
|
||||
// dd/mm/yy 07/04/2012
|
||||
// dd-M-yy 07-Apr-2012
|
||||
// d-M-yy 7-Apr-2012
|
||||
return "dd-M-yy";
|
||||
}
|
||||
}
|
||||
public string FormatDateForForm(DateTime value)
|
||||
{
|
||||
return value.Format("dd-MMM-yyyy");
|
||||
}
|
||||
public DateTime ParseDateFromForm(string value)
|
||||
{
|
||||
return DateUtil.ParseExact(value, "dd-MMM-yyyy");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Link URLs.
|
||||
public class LinksData
|
||||
{
|
||||
public string Facebook { get; } = "https://www.facebook.com/BusinessMgr/";
|
||||
public string LinkedIn { get; } = "https://www.linkedin.com/company/BusinessMgr/about/";
|
||||
}
|
||||
public LinksData Links { get; } = new LinksData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Form properties.
|
||||
/// <summary>
|
||||
/// User session index to identify the site resources, eg. database.
|
||||
/// <para>Equivalent to the Site index on the login form.</para>
|
||||
/// <para>Populates value on logout form to identify default site for next login.</para>
|
||||
/// </summary>
|
||||
public ushort SessionIdx { get { return SessionContext?.Index ?? 0; } }
|
||||
public string FormAction { get; set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
using Microsoft.AspNetCore.Html;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Sacs.Web.Components;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.Controllers;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr.Control;
|
||||
using Sarand.Net.Standard.Base.CodeTypes;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
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 Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.Models
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SbmModel_Base : SaModel
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private SbmInternals internals;
|
||||
private SbmInternals_Control internals_Control;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Protected construction.
|
||||
protected SbmModel_Base(SbmLocaliser localiser)
|
||||
{
|
||||
Localiser = localiser;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (internals != null) internals.Dispose();
|
||||
internals = null;
|
||||
if (internals_Control != null) internals_Control.Dispose();
|
||||
internals_Control = null;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Application properties.
|
||||
private SbmApplication_Web App { get { return SbmGlobals_Web.Application; } }
|
||||
protected App.SbmAppConfig AppConfig { get { return App.AppConfig; } }
|
||||
protected SbmSystem_Web System { get { return App.System_Web; } }
|
||||
public String SessionCookieName { get { return App.SessionCookieName; } }
|
||||
public SbmSessionData SessionData { get { return SessionData_Web; } }
|
||||
public SbmSessionData_Web SessionData_Web { get; set; }
|
||||
public SbmSessionContext SessionContext { get { return SessionData?.SessionContext ?? null; } }
|
||||
public abstract ISbmUserOrganisationContext UserContext_Core { get; }
|
||||
public DbUpdateInfo DbUpdateInfo { get { return SessionData?.DbUpdateInfo ?? new DbUpdateInfo(null, "", SbmSystem.ComputerName); } }
|
||||
public SbmLocaliser Localiser { get; }
|
||||
// Request properties.
|
||||
public SbmController_Web Controller { get; set; }
|
||||
public CultureInfo SessionCulture { get { return Controller?.SessionCulture ?? CultureInfo.InvariantCulture; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Page configuration.
|
||||
public String InstanceVersion { get { return !StringUtil.IsEmpty(App.AppConfig.Instance) ? App.AppConfig.Instance + " v" + Sbm.Version.GetFullVersion() : "v" + Sbm.Version.GetAppVersion(); } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Business components.
|
||||
// NB Keep these accessors protected to avoid them being called by the model binding logic before the session data is ready.
|
||||
protected SbmInternals Internals { get { if (internals == null) internals = new SbmInternals(UserContext_Core); return internals; } }
|
||||
public SbmInternals_Control Internals_Control { get { if (internals_Control == null) internals_Control = new SbmInternals_Control(); return internals_Control; } }
|
||||
// Managers.
|
||||
protected SbmAccountMgr AccountMgr { get { return Internals.AccountMgr; } }
|
||||
protected SbmAssetMgr AssetMgr { get { return Internals.AssetMgr; } }
|
||||
protected SbmCommodityMgr CommodityMgr { get { return Internals.CommodityMgr; } }
|
||||
protected SbmPriceMgr PriceMgr { get { return Internals.PriceMgr; } }
|
||||
protected SbmTransactionMgr TransactionMgr { get { return Internals.TransactionMgr; } }
|
||||
protected SbmStockMgr StockMgr { get { return Internals.StockMgr; } }
|
||||
protected SbmProcessMgr ProcessMgr { get { return Internals.ProcessMgr; } }
|
||||
protected SbmDataItemMgr DataItemMgr { get { return Internals.DataItemMgr; } }
|
||||
// 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; } }
|
||||
// Consoles.
|
||||
protected SbmSessionConsole SessionConsole { get { return Internals.SessionConsole; } }
|
||||
protected SaDiaryConsole DiaryConsole { get { return Internals.DiaryConsole; } }
|
||||
protected SaSecurityConsole SecurityConsole { get { return Internals.SecurityConsole; } }
|
||||
protected SaCodeTypeConsole CodeTypeConsole { get { return Internals.CodeTypeConsole; } }
|
||||
protected SaReferenceDataConsole ReferenceDataConsole { get { return Internals.ReferenceDataConsole; } }
|
||||
protected SaUpdateLogConsole UpdateLogConsole { get { return Internals.UpdateLogConsole; } }
|
||||
protected SaInterfaceConsole InterfaceConsole { get { return Internals.InterfaceConsole; } }
|
||||
protected SaItemDocConsole ItemDocConsole { get { return Internals.ItemDocConsole; } }
|
||||
protected SaItemOptionConsole ItemOptionConsole { get { return Internals.ItemOptionConsole; } }
|
||||
protected SaItemDataConsole ItemDataConsole { get { return Internals.ItemDataConsole; } }
|
||||
// Configurations.
|
||||
protected SbmStockControlConfig StockControlConfig { get { return Internals.StockControlConfig; } }
|
||||
protected SbmRequirementCostingConfig RequirementCostingConfig { get { return Internals.RequirementCostingConfig; } }
|
||||
// System codes.
|
||||
protected List<TypeCodeDesc> GetCodesOfType(Sbm.SystemCode systemCode) { return Internals.GetSystemCodes(systemCode); }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Security.
|
||||
public bool ValidUserSession { get { return SessionData?.ValidUser ?? false; } }
|
||||
public bool AwaitingLogin { get { return !ValidUserSession; } }
|
||||
public bool KeepLoggedIn { get { return !AwaitingLogin && SessionData_Web.KeepLoggedIn; } }
|
||||
/// <summary>Maximum length allowed for password entry: sign-up, change password etc.</summary>
|
||||
public int PasswordMaxLength { get; } = 32;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Form control value max length - Security tables.
|
||||
/// <para>In many cases the database columns allow plenty of extra space for the value, in case they need to be encrypted.</para>
|
||||
/// <para>Hence, several cases where the value entered in the control isn't allowed the full database length.</para>
|
||||
/// </summary>
|
||||
public int GetControlMaxLength(SaSecurityDbDfn.ColumnIdx column)
|
||||
{
|
||||
int maxLength = (int)SaSecurityDbDfn.GetColTextLen(column);
|
||||
switch (column)
|
||||
{
|
||||
case SaSecurityDbDfn.ColumnIdx.SaSecItem_EmailAddress:
|
||||
return Math.Min(maxLength, 100);
|
||||
}
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Form control value max length - code type tables.
|
||||
/// <para>In many cases the database columns allow plenty of extra space for the value, in case they need to be encrypted.</para>
|
||||
/// <para>Hence, several cases where the value entered in the control isn't allowed the full database length.</para>
|
||||
/// </summary>
|
||||
public int GetControlMaxLength(SaCodeTypeDbDfn.ColumnIdx column)
|
||||
{
|
||||
int maxLength = (int)SaCodeTypeDbDfn.GetColTextLen(column);
|
||||
switch (column)
|
||||
{
|
||||
case SaCodeTypeDbDfn.ColumnIdx.SaCodeType_Name:
|
||||
case SaCodeTypeDbDfn.ColumnIdx.SaCode_Description:
|
||||
return Math.Min(maxLength, 100);
|
||||
}
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Form control value max length - BusinessMgr tables.
|
||||
/// <para>In many cases the database columns allow plenty of extra space for the value, in case they need to be encrypted.</para>
|
||||
/// <para>Hence, several cases where the value entered in the control isn't allowed the full database length.</para>
|
||||
/// </summary>
|
||||
public int GetControlMaxLength(SbmDbDfn.ColumnIdx column)
|
||||
{
|
||||
int maxLength = (int)SbmDbDfn.GetColTextLen(column);
|
||||
switch (column)
|
||||
{
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_Email:
|
||||
return Math.Min(maxLength, 100);
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_FirstName:
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_LastName:
|
||||
return Math.Min(maxLength, 40);
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_Name:
|
||||
return Math.Min(maxLength, 80);
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_PhoneMain:
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_PhoneMobile:
|
||||
case SbmDbDfn.ColumnIdx.Affiliate_PhoneAlt:
|
||||
return Math.Min(maxLength, 20);
|
||||
case SbmDbDfn.ColumnIdx.Address_Postcode:
|
||||
return Math.Min(maxLength, 16);
|
||||
}
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copyright notice.
|
||||
public HtmlString CopyrightNotice
|
||||
{
|
||||
get
|
||||
{
|
||||
int initialYear = 2020;
|
||||
int currentYear = DateTime.Today.Year;
|
||||
return Localiser.GetHtmlText("copyright.symbol.year.html", (initialYear != currentYear ? initialYear + "-" : "") + currentYear.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Display data - Dates.
|
||||
public String FormatDateForDisplay(DateTime? value)
|
||||
{
|
||||
return DateUtil.Format(value, "d-MMM-yy", SessionCulture);
|
||||
}
|
||||
public String FormatDateTimeForDisplay(DateTime? value)
|
||||
{
|
||||
return StringUtil.TrimAll(DateUtil.Format(value, "d-MMM-yy HH:mm", SessionCulture));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Form data - Dates.
|
||||
// Format may depend on locale, but as long as these methods are used consistently,
|
||||
// there should be consistent formatting, display and parsing of date values.
|
||||
public String CalendarDateFormat
|
||||
{
|
||||
get
|
||||
{
|
||||
// JQuery-UI DatePicker date format.
|
||||
// Format:
|
||||
// d Single digit day of month
|
||||
// dd Double digit day of month
|
||||
// D 3 letter day of week abbreviation.
|
||||
// DD Day of week.
|
||||
// m Single digit month.
|
||||
// mm Double digit month.
|
||||
// M 3 letter month abbreviation.
|
||||
// MM Month name.
|
||||
// yy 4 digit year.
|
||||
// Examples:
|
||||
// dd/mm/yy 07/04/2012
|
||||
// dd-M-yy 07-Apr-2012
|
||||
// d-M-yy 7-Apr-2012
|
||||
return "dd-M-yy";
|
||||
}
|
||||
}
|
||||
public String FormatDateForForm(DateTime value)
|
||||
{
|
||||
return DateUtil.Format(value, "dd-MMM-yyyy");
|
||||
}
|
||||
public DateTime ParseDateFromForm(String value)
|
||||
{
|
||||
return DateUtil.ParseExact(value, "dd-MMM-yyyy");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Link URLs.
|
||||
public class LinksData
|
||||
{
|
||||
public String Facebook { get; } = "https://www.facebook.com/BusinessMgr/";
|
||||
public String LinkedIn { get; } = "https://www.linkedin.com/company/BusinessMgr/about/";
|
||||
}
|
||||
public LinksData Links { get; } = new LinksData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Form data.
|
||||
// NB Use methods rathe rthan accessors for properties that depend on session data
|
||||
// to avoid the model binding logic invoking a getter before it's ready for use.
|
||||
|
||||
/// <summary>List of Code Types for dropdown.</summary>
|
||||
public IEnumerable<SelectListItem> GetCodeTypesForSelect()
|
||||
{
|
||||
List<CodeDesc> codeTypes = new List<CodeDesc>();
|
||||
SaCodeType.Params prmCodeType = new SaCodeType.Params();
|
||||
prmCodeType.SortColumns.Add(CodeTypeConsole.GetCodeTypeColumnDfn(SaCodeType.Column.Name));
|
||||
foreach (SaCodeType codeType in CodeTypeConsole.GetCodeTypeList(prmCodeType))
|
||||
codeTypes.Add(codeType.Code, codeType.Name);
|
||||
return new SelectList(codeTypes, "Code", "Desc");
|
||||
}
|
||||
|
||||
/// <summary>List of Code Type Codes for dropdown.</summary>
|
||||
public IEnumerable<SelectListItem> GetCodeTypeCodesForSelect(Sbm.ApplCodeType codeType, bool activeOnly = true)
|
||||
{
|
||||
List<CodeDesc> codes = new List<CodeDesc>();
|
||||
foreach (SaCode code in CodeTypeConsole.GetCodesForCodeType(SbmSystem.GetCodeTypeCode(codeType), activeOnly))
|
||||
codes.Add(code.Code, code.Description);
|
||||
return new SelectList(codes, "Code", "Desc");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Form properties.
|
||||
/// <summary>
|
||||
/// User session index to identify the site resources, eg. database.
|
||||
/// <para>Equivalent to the Site index on the login form.</para>
|
||||
/// <para>Populates value on logout form to identify default site for next login.</para>
|
||||
/// </summary>
|
||||
public ushort SessionIdx { get { return SessionContext?.Index ?? 0; } }
|
||||
public String FormAction { get; set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user