My C# code is returning the first phone number in the xml document regardless of its type.
But the requirement is that my C# code should return only one phone number based on type found in xml document in a certain order.
There are 4 types of phone numbers as you will see in the xml document code I have posted here below.
The condition to display the phone number by type is as follows:
1. Check in the xml for Phone Current ="true". After that display the phone number where Type Word ="HOME" first. If this type is not found, look for Type Word ="CELL" and display it. If this is not found then look for Type Word ="WORK" and display it. If all above Types are not found look for Type Word="FAX" and display the fax number.
xml document
C# code
But the requirement is that my C# code should return only one phone number based on type found in xml document in a certain order.
There are 4 types of phone numbers as you will see in the xml document code I have posted here below.
The condition to display the phone number by type is as follows:
1. Check in the xml for Phone Current ="true". After that display the phone number where Type Word ="HOME" first. If this type is not found, look for Type Word ="CELL" and display it. If this is not found then look for Type Word ="WORK" and display it. If all above Types are not found look for Type Word="FAX" and display the fax number.
xml document
C#:
<?xml version="1.0" encoding="UTF-8"?>
< Integration>
<Party ID="1">
<Phone>
<Type Word="WORK">Work</Type>
<Number>218-222-2222</Number>
</Phone>
<Phone Current="true">
<Type Word="FAX">Fax</Type>
<Number>218-777-7777</Number>
</Phone>
<Phone>
<Type Word="HOME">Home</Type>
<Number>218-333-3333</Number>
</Phone>
<Phone>
<Type Word="CELL">Cell</Type>
<Number>218-555-5555</Number>
</Phone>
<Phone Current="true">
<Type Word="CELL">Cell</Type>
<Number>218-666-6666</Number>
</Phone>
<Phone Current="true">
<Type Word="HOME">Home</Type>
<Number>218-300-0011</Number>
</Phone>
<Phone Current="true">
<Type Word="WORK">Work</Type>
<Number>218-111-0000</Number>
</Phone>
<Phone>
<Type Word="FAX">Fax</Type>
<Number>218-000-9999</Number>
</Phone>
< /Integration>
C# code
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace Msc.Integration.Mncis.Service.v4
{
class InsertUpdateCase : CamperUpdates
{
public void ProcessInsertUpdateCase(ref Msc.Integration.MessageBroker.Library.v4.Broker aobjBroker, ref System.Xml.XmlDocument aobjXmlInputDoc, ref Microsoft.VisualBasic.Collection aobjInstantiatedObjectsCollection, XmlNode aobjxmNotificationEventNode)
/// <summary>
/// </summary>
/// <param name="objxmlBasePartyNode"></param>
/// <param name="objxmlCasePartyNode"></param>
/// <param name="objxmlBasePartyAddressNode"></param>
/// <param name="objCaseParty"></param>
protected void GetParty(ref XmlNode objxmlBasePartyNode, XmlNode objxmlCasePartyNode, ref XmlNode objxmlBasePartyAddressNode, ref ConservatorService.CaseParty objCaseParty, string astrDescription)
{
objCaseParty.PartyId = objxmlBasePartyNode.SelectSingleNode("@ID").InnerText;
objCaseParty.PartyType = (ConservatorService.MncisPartyTypes)Enum.Parse(typeof(ConservatorService.MncisPartyTypes), astrDescription);
Boolean blnPhoneFound = false;
XmlNode objxmlPhoneNode = objxmlBasePartyNode.SelectSingleNode("Phone[@Current='true']");
if (objxmlPhoneNode != null)
{
objCaseParty.Phone = new ConservatorService.Phone();
if (objxmlPhoneNode.SelectSingleNode("Type").InnerText == "Home")
{
objCaseParty.Phone.Type = ConservatorService.PhoneNumberTypes.Home;
blnPhoneFound = true;
}
else //Cell
{
if (objxmlPhoneNode.SelectSingleNode("Type").InnerText == "Cell")
{
objCaseParty.Phone.Type = ConservatorService.PhoneNumberTypes.Cell;
blnPhoneFound = true;
}
else //Work
{
if (objxmlPhoneNode.SelectSingleNode("Type").InnerText == "Work")
{
objCaseParty.Phone.Type = ConservatorService.PhoneNumberTypes.Work;
blnPhoneFound = true;
}
else //Fax
{
if (objxmlPhoneNode.SelectSingleNode("Type").InnerText == "Fax")
{
objCaseParty.Phone.Type = ConservatorService.PhoneNumberTypes.Fax;
blnPhoneFound = true;
}
} //Fax
} //Work
} // Cell
if (blnPhoneFound)
{
if (objxmlPhoneNode.SelectSingleNode("Extension") != null)
{
string strExtension = objxmlPhoneNode.SelectSingleNode("Extension").InnerText;
objCaseParty.Phone.Extention = strExtension;
}
if (objxmlPhoneNode.SelectSingleNode("Number") != null)
{
string strNumber = objxmlPhoneNode.SelectSingleNode("Number").InnerText;
objCaseParty.Phone.Number = strNumber;
}
}
} //Phone Current
}
}
}