using Sarand.Core.App; using Sarand.Core.Base; using Sarand.Core.Dbas.Base; using Sarand.OperationsMgr.Web.App; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Sarand.OperationsMgr.Web.Models { //======================================================================= public class Model_Base { //------------------------------------------------------------------- // Data members. private readonly List infoMessages = new List(); private readonly List warningMessages = new List(); private readonly List errorMessages = new List(); //------------------------------------------------------------------- // Protected construction - use derived class. protected Model_Base () { } //------------------------------------------------------------------- // Application properties. protected SaOperationsMgrWebApp App { get { return SaOperationsMgrWebApp.GetInstance(); } } public bool OK { get { return !HasMessages; } } public bool AwaitingLogin { get; set; } = true; //------------------------------------------------------------------- // Session profile. public SessionData SessionData { get; set; } //------------------------------------------------------------------- // Business Object Managers. //------------------------------------------------------------------- // Version parameter for includes. public String HrefVersion { get { DateTime versionDate = SacsSystem.AssemblyBuildAt; if (!DateUtil.IsValid(versionDate) || SacsSystem.DebugMode) versionDate = DateTime.Now; return DateUtil.Format(versionDate, "yyyyMMdd" /*+ (SacsSystem.Debug ? "HHmm" : "")*/); } } // Additional includes. public List AdditionalFiles_CSS { get; set; } = new List(); public List AdditionalFiles_JS { get; set; } = new List(); //------------------------------------------------------------------- // Redirection locations. public class RedirectLocationData { // Properties populated in Controller_Base.OnActionExecuted. public String Home { get; internal set; } public String Home_SessionExpired { get; internal set; } } public RedirectLocationData RedirectLocation { get; } = new RedirectLocationData(); //------------------------------------------------------------------- // Paging properties. private readonly DbQuery.Paging dataPaging = new DbQuery.Paging(); public bool DataPaged { get { return dataPaging.Paged; } } public uint DataPageNo { get { return dataPaging.PageNo; } set { dataPaging.PageNo = value; } } public ushort DataPageLength { get { return dataPaging.PageLength; } set { dataPaging.PageLength = value; } } public uint DataPageCount { get { return (DataPageLength > 0 ? (uint)Math.Ceiling((decimal)DataItemTotal / DataPageLength) : 0); } } public uint DataItemCount { get; set; } public uint DataItemTotal { get; set; } //------------------------------------------------------------------- // Form properties. /// /// User session index to identify the site resources, eg. database. /// Equivalent to the Site index on the login form. /// Populates value on logout form to identify default site for next login. /// public ushort SessionIdx { get; set; } public String FormAction { get; set; } //------------------------------------------------------------------- // Message properties. public virtual bool ShowMessagesAtTopOfBody { get; } = true; public bool HasMessages { get { return (infoMessages.Count > 0 || warningMessages.Count > 0 || errorMessages.Count > 0); } } public List InfoMessages { get { return new List(infoMessages); } } public List WarningMessages { get { return new List(warningMessages); } } public List ErrorMessages { get { return new List(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); } //------------------------------------------------------------------- } //======================================================================= }