Part of a system I am working on manages some securities information (stocks, bonds, etc...) and business rules specify certain fields be displayed only in all CAPS (stock symbols and CUSIPs for example). Users will have to look at data displayed on the screen as well as perform create/edit data-entry operations.
Where is the best place to deal with this?
1. Presentation layer only
user enters "ibm" as stock symbol, stored in database as "ibm", converted to uppercase when displayed in app ("IBM")
2. Convert to CAPS before storing in DB
user enters "ibm", model class converts to uppercase and sends to database, stored as "IBM"
Something like a custom setter:
private string _StockSymbol;
public string StockSymbol
{
get { return _StockSymbol; }
set
{
if (value != null)
value = value.ToUpper();
_StockSymbol = value;
}
}
3. Convert to CAPS at DB
user enters "ibm", database insert query converts to "IBM" (for example, using the UPPER
function in SQL)
The end result is the same for the users - they see their data in all CAPS and the system doesn't care if their data input is in the proper case or not. The most "MVC compliant" answer seems to be #1, but if this data will never be used in any other format other than all CAPS, I would argue it should be validated as such before being stored in the database. That then becomes more of a controller or view model concern, right?
I've heard people speak about accomplishing this client-side with Java (and even CSS), but that seems like a very poor solution.
I think the question is language/system-agnostic, but if it matters, I'm using MS SQL with Entity Framework/ASP.Net MVC.
What I'm scratching my head over is whether or not a presentational business rule like this should influence how the data is stored in the DB (CAPS vs no CAPS). The application doesn't care if the stock symbol IBM is input as "iBm" or "ibM" but it seems wrong to store the data like that (it will only ever be used/displayed in CAPS).
Would you consider this a data validation issue to be handled at the controller/model level, or a presentational detail to be handled only at the view?