254 lines
11 KiB
C#
254 lines
11 KiB
C#
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.Mgr;
|
|
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 class SbmModel_Base : SaModel
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private SbmInternals internals;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Protected construction.
|
|
protected SbmModel_Base(SbmLocaliser localiser)
|
|
{
|
|
Localiser = localiser;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Application properties.
|
|
private SbmApplication_Web App { get { return SbmGlobals_Web.Application; } }
|
|
protected 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 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 teh model binding logic before the session data is ready.
|
|
protected SbmInternals Internals { get { if (internals == null) internals = new SbmInternals(SessionData_Web); return internals; } }
|
|
// 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; } }
|
|
// Consoles.
|
|
protected SbmConfigConsole ConfigConsole { get { return Internals.ConfigConsole; } }
|
|
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.GetCodesOfType(systemCode); }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Security.
|
|
public bool ValidUserSession { get { return SessionData?.ValidUserSession ?? false; } }
|
|
public bool AwaitingLogin { get { return !ValidUserSession; } }
|
|
public bool KeepLoggedIn { get { return !AwaitingLogin && SessionData.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 - 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 Address Types for dropdown.</summary>
|
|
public IEnumerable<SelectListItem> GetAddressTypeCodesForSelect()
|
|
{
|
|
return new SelectList(GetCodesOfType(Sbm.SystemCode.AddressType), "Code", "Desc");
|
|
}
|
|
|
|
/// <summary>List of Affiliate Types for dropdown.</summary>
|
|
public IEnumerable<SelectListItem> GetAffiliateTypeCodesForSelect()
|
|
{
|
|
return new SelectList(GetCodesOfType(Sbm.SystemCode.AffiliateType), "Code", "Desc");
|
|
}
|
|
|
|
/// <summary>List of Association Types for dropdown.</summary>
|
|
public IEnumerable<SelectListItem> GetAssociationTypeCodesForSelect()
|
|
{
|
|
return new SelectList(GetCodesOfType(Sbm.SystemCode.AssociationType), "Code", "Desc");
|
|
}
|
|
|
|
/// <summary>List of Commodity Types for dropdown.</summary>
|
|
public IEnumerable<SelectListItem> GetCommodityTypeCodesForSelect()
|
|
{
|
|
|
|
return new SelectList(GetCodesOfType(Sbm.SystemCode.CommodityType), "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; }
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|