Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

CRUD_Lib

Module containing actions and structures used to standardize CRUD operations.

Structures
 EntityActionMessage
o Structure containing a message and message type (i.e., error, warning, info, success).
Typically, holds the error/s encountered during CRUD operations.
 EntityActionResult
o Expected output for all CRUD operations. Contains an IsSuccess boolean flag, the
combined output message text and type, and a list of EntityActionMessages.

Server Actions
 EntityActionResult_CombineEntityActionMessages
o Input: EntityActionMessage list
o Output: CombinedEntityActionMessageText, CombinedEntityActionMessageType
o Combines all messages during the CRUD operation to one text variable separated by a
new line. Message type is determined by the following hierarchy: Error > Warning > Info
> Success (e.g., in an operation with multiple success and errors, combined type is
error). Typically used for CRUD operations with failed validations.
 EntityActionResult_BuildFromSuccess
o Input: EntityActionResultMessageText
o Output: EntityActionResult
o Accepts a “Success” prompt and sets the IsSuccess flag to true. Used for a successful
CRUD operation.
 EntityActionResult_BuildFromError
o Input: EntityActionResultMessageText
o Output: EntityActionResult
o Accepts a “Failed” prompt and sets the IsSuccess flag to false. Typically used for a CRUD
operations with errors.
 Session_GetNormalizedSessionUserId
o If session exists, returns the active user’s Id (CRUD operations coming from the UI); else,
returns the default system user Id (CRUD operations initiated by system processes e.g.,
timers, BPT, etc.).

CRUD best practice


General
- Use camel-case (SIFRecord [wrong], SifRecord [correct]; IOMSIUser [wrong], IomsSiUser
[correct])
- Place CRUD wrappers on separate folders per entity.
- Naming conventions:
o CRUD Operation: {Entity}_{Operation}
o Input Record: Source
o Input/Output Id: Id
o Output: EntityActionResult

Entity_Upsert (Update/Insert)
CRUD wrapper for creating and updating entity records.

 Input: Entity record (Source)


 Output: Record Id (Id), EntityActionResult
 Contains validations, assignments, Create/Update entity, error handler, and return value/s.
 Sample implementation (refer to SIF_CS):

Entity_Validate
CRUD wrapper for validating record. Used to validate format, null values, date ranges, min/max
values/lengths, etc.

 Input: Entity record (Source)


 Output: EntityActionResult
 Sample implementation (refer to SIF_CS):

Entity_Remove (Delete)
CRUD wrapper used for soft/hard deleting records.
 Input: Entity Id (Id)
 Output: EntityActionResult
 Sample Implementation (refer to SIF_CS):

Entity_GetCanRemove
CRUD wrapper that validates if record is safe to remove.
 Input: Entity Id (Id)
 Output: EntityActionResult
 Sample Implementation (refer to SIF_CS):

You might also like