-
Notifications
You must be signed in to change notification settings - Fork 44
ISuccessOrErrors
GenericServices tries to provide superior error checking and reporting back to the user. It does this by validating and then catching any errors at each level in the system and feeding them back in a human readable form, or if successful it provides an appropriate success message. For a full review of all the validation levels available to the developer I recommend you read my Simple-Talk article Catching Bad Data in Entity Framework.
All commands, apart apart from ListService
return a status class, based around the ISuccessOrErrors
interface/class found the GenericLibsBase. If the method is successful the property .IsValid
is true and the property SuccessMessage
has a confirmation message.
If the property .IsValid
is false then the List property Errors
contains a list of errors.
The Create, Update and Delete methods in GenericServices use this status interface to provide user-friendly messages on to how their operation went. For instance it traps any validation errors found by EF and a small subset of SQL errors and returns them as human friendly strings. It also provides a human friendly confirmation message if the method was successful.
The DetailService
and UpdateSetupService
methods need to return both a status and some data, therefore they use a Generic status, ISuccessOrErrors<T>
. This can catch whether the requested entry is missing, which can happen if another user deletes some data in between the time that a list of items appears on the screen this user clicks on a link that calls the DetailService
or UpdateSetupService
. If this is unlikely to happen you can ignore the result, but if this error happens the result will be null.
The status success message and some of the error messages use the name of the data class type in it, e.g. for a successful update of the class Person
you would get the message "Successfully updated Person.". You can change the name used in DTO type accesses by overriding the property DataItemName
. You cannot override the name in a direct access command on a database class.
Live example web sites!
Introduction/Overview
Commands and options
- Introduction to Commands
- Key interfaces
- Calculated properties
- DoNotCopyBackToDatabase attribute
- Configuration Options
Data Transfer Objects (DTOs)