Changing every single string type field at save time

Posts   
 
    
Posts: 1
Joined: 09-Sep-2008
# Posted on: 09-Sep-2008 18:28:41   

Hello all,

A customer has just decided for some reason that they wanted all strings in the database to be saved as uppercase only and with all special characters (some text might have foreign language weird characters) stripped out. The point is not whether this is a good decision or not (I don't think it is), it's their way or the highway.

Where do you think would be the best place in the LLBL extensibility scenario to implement this string manipulation on all string typed fields of all entities just before save, without having to write specific code for each entity ?

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 09-Sep-2008 18:52:56   

assuming adapter model. I would choose an event like BeforeOnSave or something and cycle through all the fields. if the field is a string munge the data. pseudo code example

foreach(IEntityField field in entity.Fields)
{
         if(field.TypeOfData == typeof(string))
            field.CurrentValue = Munge(field.CurrentValue);
}
base.OnBeforeSave(entity);

...
private string Munge(string input)
{
        return Regex.Replace(input, "special characters", string.Empty).ToUpper();
}