Setting Entity Field

Posts   
 
    
Nailian
User
Posts: 3
Joined: 17-Feb-2010
# Posted on: 17-Feb-2010 09:58:41   

Hi all we just started using llbl gen pro and it was love at first site. But i have a little question so don't shoot me down if this has an obvious awnser.

I want to change the entity value before i insert it into a DB.

I have an entity collection binded to a datagrid. Admin Users can change passwords of the users. But I want to MD5 encrypt it before i save it to the DB.

I read some documentation on auditing:

AuditInsertOfNewEntity is this what i need to implement ?

Thnx in advance.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 17-Feb-2010 10:49:53   

Yes, or Valiudation -> ValidateEntityBeforeSave Depends on how semanticaly you define this action simple_smile

Nailian
User
Posts: 3
Joined: 17-Feb-2010
# Posted on: 17-Feb-2010 13:18:03   

Walaa wrote:

Yes, or Valiudation -> ValidateEntityBeforeSave Depends on how semanticaly you define this action simple_smile



 public override void ValidateEntityBeforeSave(IEntityCore involvedEntity)
        {
            DmUsersEntity toValidate = (DmUsersEntity)involvedEntity;

            toValidate.Password = HashString(toValidate.Password);

            base.ValidateEntityBeforeSave(involvedEntity);
        }

        private string HashString(string Value)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] data = System.Text.Encoding.ASCII.GetBytes(Value);
            data = x.ComputeHash(data);
            string ret = "";
            for (int i = 0; i < data.Length; i++)
                ret += data[i].ToString("x2").ToLower();
            return ret;
        }


Worked like a charm thnx !