Monday, February 16, 2009

Dynamic Entity Add Attribute Helper Methods

Examples: Calling the below methods:

string strDaysAttributeName = "cap_actualeffortdays";
string strHoursAttributeName = "cap_actualefforthours";
 
if (ObjProject.Properties.Contains(strDaysAttributeName))
    ((CrmNumber)ObjProject.Properties[strDaysAttributeName]).Value = iDays;
else
    CrmHelper.AddNumberProperty(ObjProject, strDaysAttributeName, iDays);

 
if (ObjProject.Properties.Contains(strHoursAttributeName))
    ((CrmNumber)ObjProject.Properties[strHoursAttributeName]).Value = iHours;
else
    CrmHelper.AddNumberProperty(ObjProject, strHoursAttributeName, iHours);


public static void AddStringProperty(DynamicEntity entity, string strColumnName, string DefaultValue)
{
    #region If Column attribute not in entity Collection 

        if (!entity.Properties.Contains(strColumnName))
        {
            StringProperty AttributeContactID = new StringProperty();
            AttributeContactID.Name = strColumnName;
            AttributeContactID.Value = DefaultValue;
        }
    #endregion If Column attribute not in entity Collection
}

 

public static void AddNumberProperty(DynamicEntity entity, string strColumnName, int DefaultValue)
{
    #region If Column attribute not in entity Collection 

        if (!entity.Properties.Contains(strColumnName))
        {
            CrmNumberProperty AttributeID = new CrmNumberProperty();
            AttributeID.Name = strColumnName;
            AttributeID.Value = new CrmNumber(DefaultValue);
        }
    #endregion If Column attribute not in entity Collection
}

No comments: