Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use VS2012, WindowsApp,c#. For my Person list, I would like to use FirstOrDefault for PrimaryPersonID and SecondaryPersonID properties.

My controls work fine in the UI, but I need logic to display properly.
If both PrimaryPersonID and SecondPersonID exists, set Primary as first.
If only a PrimaryPersonID exists and no SecondaryPersonID, Secondary can be null.
If neither exists, set null as default. So null is acceptable for both.

C#
//CaseRecord is my class
protected void ValidatePersonType(ValidationResults results)
{
    ValidationResult vr = new ValidationResult();     
    if (this.CaseRecord.PrimaryPersonID != null &&             this.CaseRecord.SecondaryPersonID != null)
{
     //this does not work
     PrimaryPersonID = CaseRecord.GetPersonByID(PersonID.Value).FirstOrDefault();
}
else
{
     if (PersonList.Count == 0)
     {
        //Not sure how to do here also	
        PrimaryPersonID == null;
        SecondaryPersonID == null;
     }
}

//and do the same for SecondaryPersonID


Any help is appreciated. If using FirstOrDefault is wrong, I just need help with correct logic. Thanks.
Posted
Updated 12-Apr-15 17:04pm
v3
Comments
Maciej Los 13-Apr-15 1:54am    
Please, look carefully on your code. Does PrimaryPersonID is variable name or variable's data type? Probably you need to set it this way: this.CaseRecord.PrimaryPersonID = CaseRecord.GetPersonByID(PersonID.Value);
Tomas Takac 13-Apr-15 3:31am    
What exactly do you mean by "this does not work" (a comment in you code).
George Swan 13-Apr-15 5:20am    
I think PrimaryPersonID == null; should read PrimaryPersonID = null;
Sam 9100 13-Apr-15 15:03pm    
I was able to get something resemble to what I wanted. thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900