Add project files.
This commit is contained in:
@@ -0,0 +1,275 @@
|
||||
using Microsoft.AspNetCore.Html;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
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 Saxonite.Base.App;
|
||||
using Saxonite.Net.Core.Web.Base.App;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Consoles;
|
||||
using Saxonite.Net.Standard.Base.Mgr;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Base.Models
|
||||
{
|
||||
//=======================================================================
|
||||
public class SaxModel_Base
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private SaxInternals internals;
|
||||
private readonly List<String> infoMessages = new List<string>();
|
||||
private readonly List<String> warningMessages = new List<string>();
|
||||
private readonly List<String> errorMessages = new List<string>();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Protected construction.
|
||||
protected SaxModel_Base(SaxLocaliser localiser)
|
||||
{
|
||||
Localiser = localiser;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Application properties.
|
||||
private SaxApplication_Web App { get { return SaxApplication_Web.WebApp; } }
|
||||
protected SaxSessionConfig SessionConfig { get { return App.SessionConfig; } }
|
||||
protected SaxSystem_Web System { get { return App.System_Web; } }
|
||||
public String SessionCookieName { get { return App.SessionCookieName; } }
|
||||
public SaxSessionData SessionData { get; set; }
|
||||
public SaxSessionContext SessionContext { get { return SessionData?.SessionContext ?? App.SessionContext; } }
|
||||
public DbUpdateInfo DbUpdateInfo { get { return SessionData?.DbUpdateInfo ?? new DbUpdateInfo(null, "", SaxSystem.ComputerName); } }
|
||||
public bool DebugMode { get { return SaxSystem.DebugMode; } }
|
||||
public SaxLocaliser Localiser { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Business components.
|
||||
protected SaxInternals Internals { get { if (internals == null) internals = new SaxInternals(SessionContext); return internals; } }
|
||||
// Consoles.
|
||||
protected SaxDataCacheConsole DataCacheConsole { get { return Internals.DataCacheConsole; } }
|
||||
// Managers.
|
||||
protected SaxReferenceMgr ReferenceMgr { get { return Internals.ReferenceMgr; } }
|
||||
protected SaxAccountMgr AccountMgr { get { return Internals.AccountMgr; } }
|
||||
protected SaxActivityMgr ActivityMgr { get { return Internals.ActivityMgr; } }
|
||||
protected SaxItemDataMgr ItemDataMgr { get { return Internals.ItemDataMgr; } }
|
||||
// System codes.
|
||||
public List<TypeCodeDesc> RegionTypes { get { return Internals.RegionTypes; } }
|
||||
public List<TypeCodeDesc> UserRoles { get { return Internals.UserRoles; } }
|
||||
public List<TypeCodeDesc> OrganisationTypes { get { return Internals.OrganisationTypes; } }
|
||||
public List<TypeCodeDesc> OrganisationCategories { get { return Internals.OrganisationCategories; } }
|
||||
public List<TypeCodeDesc> OrganisationRoles { get { return Internals.OrganisationRoles; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Page configuration.
|
||||
public bool OK { get { return !HasMessages(); } }
|
||||
public virtual bool ProhibitCache { get; set; } = true;
|
||||
public String PageCaption { get; set; }
|
||||
public String InstanceVersion { get { return !StringUtil.IsEmpty(App.SessionConfig.Instance) ? App.SessionConfig.Instance + " v" + Sax.Version.GetFullVersion() : "v" + Sax.Version.GetAppVersion(); } }
|
||||
public bool IncludeGoogleAnalytics { get; set; } = false;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Security.
|
||||
public bool ValidUserSession { get { return SessionData?.ValidUserSession ?? false; } }
|
||||
public bool AwaitingLogin { get { return !ValidUserSession; } }
|
||||
public bool KeepLoggedIn { get { return !AwaitingLogin && SessionData.User.KeepLoggedIn; } }
|
||||
/// <summary>Maximum length allowed for password entry: sign-up, change password etc.</summary>
|
||||
public int PasswordMaxLength { get; } = 32;
|
||||
|
||||
// Account actions.
|
||||
// NB The form proerty will never be used - account actions processed within page.
|
||||
public String AccountAction { get; set; }
|
||||
public IEnumerable<SelectListItem> GetAccountActions()
|
||||
{
|
||||
List<CodeDesc> items = new List<CodeDesc>();
|
||||
if (SessionData?.ValidUserSession ?? false)
|
||||
{
|
||||
items.Add("Profile", Localiser["label.view.profile"]);
|
||||
items.Add("ChangePassword", Localiser["label.change.password"]);
|
||||
items.Add("SignOut", Localiser["label.sign.out"]);
|
||||
}
|
||||
return new SelectList(items, "Code", "Desc");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Form control value max length.
|
||||
/// <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(SaxDbDfn.ColumnIdx column)
|
||||
{
|
||||
int maxLength = (int)SaxDbDfn.GetColTextLen(column);
|
||||
switch (column)
|
||||
{
|
||||
case SaxDbDfn.ColumnIdx.UserAccount_EmailAddress:
|
||||
return Math.Min(maxLength, 60);
|
||||
case SaxDbDfn.ColumnIdx.UserAccount_FirstName:
|
||||
case SaxDbDfn.ColumnIdx.UserAccount_LastName:
|
||||
return Math.Min(maxLength, 40);
|
||||
case SaxDbDfn.ColumnIdx.Organisation_Name:
|
||||
return Math.Min(maxLength, 80);
|
||||
case SaxDbDfn.ColumnIdx.UserAccount_PhoneMain:
|
||||
case SaxDbDfn.ColumnIdx.UserAccount_PhoneMobile:
|
||||
case SaxDbDfn.ColumnIdx.Organisation_PhoneMain:
|
||||
case SaxDbDfn.ColumnIdx.Organisation_PhoneAlt:
|
||||
return Math.Min(maxLength, 20);
|
||||
//case SaxDbDfn.ColumnIdx.UserAccount_Postcode:
|
||||
//case SaxDbDfn.ColumnIdx.ItemAddress_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());
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Link URLs.
|
||||
public class LinksData
|
||||
{
|
||||
public String Facebook { get; } = "https://www.facebook.com/saxonite/";
|
||||
public String LinkedIn { get; } = "https://www.linkedin.com/company/saxonite/about/";
|
||||
}
|
||||
public LinksData Links { get; } = new LinksData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Form data.
|
||||
/// <summary>List of Yes/No options for dropdown.</summary>
|
||||
public IEnumerable<SelectListItem> YesNoOptionsForSelect
|
||||
{
|
||||
get { return new SelectList(SaxSystem.GetCodesOfType(Sax.CodeType.YesNo), "Code", "Desc"); }
|
||||
}
|
||||
|
||||
/// <summary>List of titles for dropdown.</summary>
|
||||
public IEnumerable<SelectListItem> TitlesForSelect
|
||||
{
|
||||
get { return new SelectList(SaxSystem.GetCodesOfType(Sax.CodeType.Title), "Code", "Desc"); }
|
||||
}
|
||||
|
||||
/// <summary>List of Region Types for dropdown.</summary>
|
||||
public IEnumerable<SelectListItem> RegionTypesForSelect
|
||||
{
|
||||
get { return new SelectList(RegionTypes, "Code", "Desc"); }
|
||||
}
|
||||
|
||||
/// <summary>List of Organisation Types for dropdown.</summary>
|
||||
public IEnumerable<SelectListItem> OrganisationTypesForSelect
|
||||
{
|
||||
get { return new SelectList(OrganisationTypes, "Code", "Desc"); }
|
||||
}
|
||||
|
||||
/// <summary>List of Organisation Categories for dropdown.</summary>
|
||||
public IEnumerable<SelectListItem> OrganisationCategoriesForSelect
|
||||
{
|
||||
get { return new SelectList(OrganisationCategories, "Code", "Desc"); }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Version parameter for includes.
|
||||
public String HrefVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTime versionDate = SaxSystem.AssemblyBuildAt;
|
||||
if (!DateUtil.IsValid(versionDate) || SaxSystem.DebugMode)
|
||||
versionDate = DateTime.Now;
|
||||
return DateUtil.Format(versionDate, "yyyyMMdd" /*+ (SacsSystem.Debug ? "HHmm" : "")*/);
|
||||
}
|
||||
}
|
||||
// Additional includes.
|
||||
public List<String> AdditionalFiles_CSS { get; set; } = new List<string>();
|
||||
public List<String> AdditionalFiles_JS { get; set; } = new List<string>();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Redirection locations.
|
||||
public class RedirectLocationData
|
||||
{
|
||||
// Properties populated in Controller_Base.OnActionExecuted.
|
||||
public String Base { get; internal set; }
|
||||
public String Home { get; internal set; }
|
||||
public String Home_SessionExpired { get; internal set; }
|
||||
}
|
||||
public RedirectLocationData RedirectLocation { get; } = new RedirectLocationData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Paging properties.
|
||||
private class DataPaging
|
||||
{
|
||||
private DbQuery.Paging paging { get; } = new DbQuery.Paging();
|
||||
public void PopulatePagingTo(DbQuery.Paging resultsPaging)
|
||||
{
|
||||
resultsPaging.PageLength = paging.PageLength;
|
||||
resultsPaging.PageNo = paging.PageNo;
|
||||
}
|
||||
public bool IsPaged { get { return paging.Paged; } }
|
||||
public uint PageNo { get { return paging.PageNo; } set { paging.PageNo = value; } }
|
||||
public ushort PageLength { get { return paging.PageLength; } set { paging.PageLength = value; } }
|
||||
public uint PageCount { get { return (PageLength > 0 ? (uint)Math.Ceiling((decimal)ItemTotal / PageLength) : 0); } }
|
||||
public ushort ItemCount { get; set; }
|
||||
public ulong ItemTotal { get; set; }
|
||||
}
|
||||
private DataPaging Paging { get; } = new DataPaging();
|
||||
public bool DataPaged { get { return Paging.IsPaged; } }
|
||||
public uint DataPageNo { get { return Paging.PageNo; } set { Paging.PageNo = value; } }
|
||||
public ushort DataPageLength { get { return Paging.PageLength; } set { Paging.PageLength = value; } }
|
||||
public uint DataPageCount { get { return (DataPageLength > 0 ? (uint)Math.Ceiling((decimal)DataItemTotal / DataPageLength) : 0); } }
|
||||
public ushort DataItemCount { get; set; }
|
||||
public ulong DataItemTotal { get; set; }
|
||||
public void PopulatePagingTo(DbQuery.Paging resultsPaging)
|
||||
{
|
||||
Paging.PopulatePagingTo(resultsPaging);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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; } }
|
||||
public String FormAction { get; set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Messages.
|
||||
//-------------------------------------------------------------------
|
||||
public bool HasMessages()
|
||||
{
|
||||
return infoMessages.Count > 0 || warningMessages.Count > 0 || errorMessages.Count > 0;
|
||||
}
|
||||
public List<String> InfoMessages { get { return new List<string>(infoMessages); } }
|
||||
public List<String> WarningMessages { get { return new List<string>(warningMessages); } }
|
||||
public List<String> ErrorMessages { get { return new List<string>(errorMessages); } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Form messages.
|
||||
public void AddInfoMessage(String message)
|
||||
{
|
||||
if (StringUtil.IsEmpty(StringUtil.TrimAll(message))) return;
|
||||
infoMessages.Add(message);
|
||||
}
|
||||
public void AddWarningMessage(String message)
|
||||
{
|
||||
if (StringUtil.IsEmpty(StringUtil.TrimAll(message))) return;
|
||||
warningMessages.Add(message);
|
||||
}
|
||||
public void AddErrorMessage(String message)
|
||||
{
|
||||
if (StringUtil.IsEmpty(StringUtil.TrimAll(message))) return;
|
||||
errorMessages.Add(message);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user