clsModelBase¶
clsModelBase is the screen model base class every SAIF screen's concrete model derives from. It holds the screen's clsContext and user clsPreferences, defines the validate-then-write contract (ValidateData → WriteData, exposed publicly as Write) that Validate and write the model documents, performs one-time initialization and preference loading through Pre_Init (called from clsControllerBase.Initialize), and supplies a small set of protected string/date validation helpers reused by derived screens' own ValidateData implementations.
Purpose¶
- Gates every model write behind the derived screen's own validation, so
WriteDatais only ever called whenValidateDatareturnsTrue(BR-MVC-029). - Performs one-time model initialization and user-preference loading on first use per instance, via
Pre_Init(BR-MVC-016). - Carries the screen's
clsContext, giving every model access to the established security principal, cross-application context values, and well-known context keys (claimId,policyNum, etc.). - Provides reusable string/number/date validation predicates so derived
ValidateDataimplementations do not each reimplement basic input checks.
Context¶
- Namespace:
SAIF.Presentation.Web.MVC* - Assembly/package:
SAIF.Presentation.Web.MVC
Public members¶
| Member | Signature | Purpose |
|---|---|---|
New |
Public Sub New() |
Constructs the model with a fresh clsContext instance |
Context |
Public Property Context() As clsContext |
The screen's context bag — security principal, well-known claim/policy fields, and cross-application context values |
LastError |
Public Property LastError() As String |
Free-form error text a derived model can set for the calling controller/screen to surface |
Preferences |
Public ReadOnly Property Preferences() As clsPreferences |
The user's preferences, loaded once by Pre_Init for the model's application/user pair |
SecurityPrincipal |
Public Property SecurityPrincipal() As clsSecurityPrincipal (marked Obsolete, favoring Context.SecurityPrincipal) |
Legacy pass-through to Context.SecurityPrincipal, retained for backward compatibility |
Write |
Protected Friend Function Write() As Boolean |
Calls the derived ValidateData(); only when it returns True does it call WriteData() and return its result, otherwise returns False without writing (BR-MVC-029) |
ValidateData |
Protected Friend MustOverride Function ValidateData() As Boolean |
Derived-class hook that validates the model's current state before a write is attempted |
WriteData |
Protected Friend MustOverride Function WriteData() As Boolean |
Derived-class hook that persists the model's current state; only invoked after ValidateData succeeds |
Initialize |
Protected Friend Overridable Sub Initialize() |
Derived-class hook called exactly once per model instance, from Pre_Init; default implementation is a no-op |
UnInitialize |
Protected Friend Overridable Sub UnInitialize() |
Derived-class hook for model teardown; default implementation is a no-op |
IsValidString |
Protected Function IsValidString(ByVal Value As String) As Boolean |
True unless the value is Nothing or, after trimming, empty |
IsValidNumber |
Protected Function IsValidNumber(ByVal Value As String) As Boolean |
True when the value is a valid non-empty string and IsNumeric |
IsValidDate |
Protected Function IsValidDate(ByVal Value As String) As Boolean |
True when the value is a valid non-empty string and IsDate |
IsValidFutureDate (string) |
Protected Function IsValidFutureDate(ByVal Value As String) As Boolean |
True when the value is a valid date string strictly later than today (compared by short date) |
IsValidFutureDate (date) |
Protected Function IsValidFutureDate(ByVal Value As Date) As Boolean |
True when the date value is strictly later than today (compared by short date) |
Behavioral notes¶
Pre_Init(Friend, called byclsControllerBase.Initializeas part of Initialize a request) is idempotent per instance: it checks an internalm_Initedflag before callingInitialize()and constructingclsPreferences, so it only runs once even if invoked multiple times against the same model instance (BR-MVC-016).Preferencesis constructed withContext.SecurityPrincipal.UserName().ToStringand the application name, so it is only safely accessible afterSecurityPrincipalhas been established (i.e., afterPre_Inithas run following a successfulSecurityCheck).
Constraints and usage notes¶
clsModelBaseisMustInherit— every screen supplies its own concrete model subclass and overridesValidateDataandWriteData(bothMustOverride).SecurityPrincipalis markedObsolete; new code should read/writeContext.SecurityPrincipaldirectly.
Note: Statements marked with
*were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
- SAIF.Presentation.Web.MVC/clsModelBase.vb