> > this.EntityList.Clear(); > this.EntityList.Add(newEntity); > this.SetCurrentEntity(this.EntityList, 0); >>
public PolicyEntity GetPolicyByPolicyPK(Guid policyPK)
{
//return this.GetEntity("PoliciesSelectByPK",
// this.CreateParameter("@PolicyPK", policyPK));
// get the requested entity
this.GetEntity("PoliciesSelectByPK",
this.CreateParameter("@PolicyPK", policyPK));
// check its status
if (this.Entity.StatusFK != (int)StatusCode.Pending)
{
// if it is not Pending then create a new entity, copy the data from the original entity
PolicyEntity oNewPolicyEntity = new PolicyEntity();
//CopyPolicyEntity(this.Entity, oNewPolicyEntity);
Type type = oNewPolicyEntity.GetType();
while (type != null)
{
UpdateForType(type, this.Entity, oNewPolicyEntity);
type = type.BaseType;
}
oNewPolicyEntity.PolicyPK = Guid.NewGuid();
// Clear the current entity list and add this one instead
this.EntityList.Clear();
this.EntityList.Add(oNewPolicyEntity);
this.SetCurrentEntity(this.EntityList, 0);
}
return this.Entity;
}
private static void UpdateForType(Type type, PolicyEntity source, PolicyEntity destination)
{
FieldInfo[] myObjectFields = type.GetFields(
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
foreach (FieldInfo fi in myObjectFields)
{
fi.SetValue(destination, fi.GetValue(source));
}
}