Base Model
General information
"ModelBase.cs" is the class that all Models inherit from that is found under the "Utilities" directory of the Business layer of the application. It enables connection to the database by providing the basic methods that serve as tools that can be used to implement logic, so the user does not need to directly interact with the database.
Methods Overview
In the following, these methods and their functionality will be explained:
UnitWork
"UnitWork" is the container of all data repositories over which communication with the database is done.
HttpWebContext
The method "HttpWebContext" stores all the information regarding the user's request, such as query strings, attached files, etc.
ThrowError
The method "ThrowError" is used when you want to catch an error and inform the user of the details of the error. It displays a pop-up window containing the error message you inserted as parameter.
Example 1:
The following code illustrates the function call:
The "EndTime" of the Model is not supposed to be earlier than the "StartTime", so if the user accidentally inputs the times falsely, a pop-up with the error message "StartTime must be less or equal EndTime." gets displayed to the user.
Example 2:
The following code illustrates the function call using an embedded variable:
Before a Production Order is fetched using an ID, it is first checked if a Production Order exists that has that ID. If not, a pop-up with the error message "$"Order {id} does not exist!" gets displayed to the user where "{id}" is the inputted id that should be checked.
When using one or more embedded variables in an error message, a "$" should precede the string that is inserted as input parameter.
ActiveUser
"ActiveUser" returns the Name of the current user.
It is a shorter alternative to "Thread.CurrentPrincipal.Identity.Name".
Example 1:
The following code illustrates the function call:
It sets the Property "userName" of the Model to "ActiveUser"
Location
"Location" returns the Plant the User is currently located at.
AccessScope
"AccessScope" returns a List of the data (Plants) the current user has access to.
Example 1:
The following code illustrates the function call:
A foreach loop iterates through the items (Plants) in AccessScope and for each one, a SelectListIitem is added to PlantList.
Example 2:
The following code illustrates the function call of "Contains" from AccessScope:
It checks if the Location of a specific order is included in the AccessScope of the user. If it is not, an error is thrown that informs the user that they do not have access to data of this Plant.
Example 3:
The following code illustrates the function call of "Contains" from AccessScope within the filter for a Fetch from a data repository:
All Production Orders get fetched whose Location is included in the AccessScope of the user and stored into the "OrderList".
DefaultScope
"DefaultScope" is the default Plant whose data the user has access to.
If the User has access to the data of the Location he is located in, then the DefaultScope is the same as their Location. However, if the User does not have access to the data of their own Location, then the first item in their AccessScope should be used as Default.
Language
"Language" is the language of the system the application is currently running on. For example, the default language is English (United States), which is stored as "en-US".
Last updated