C# code to update the Logistics postal address through AIF.
In my second post of this series, I demonstrated the creation of document service for a new entity. The post also include the solution on how to add the related postal address using AIF document service.
In order to achieve this we have added calls to some standard API's in prepareForSaveDetailsExtended() method of our service class.
In this post I am sharing the code which can be used to test the update operation on student entity with address.
In order to update the surrogate key indexed entity, we need to use the find operation for finding the entity key, and then based on the found entity key we can do the read operation which will return the Axd class instance which can be updated as per the requirement. Below is the code which will demonstrate the same requirement.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestStudentService.ServiceReference1;//Added namespace o access service in below application
namespace TestStudentService
{
class Program
{
static void Main(string[] args)
{
int rollNumber = 4;
AxdStudentTable studentAxd = null;
CallContext context = new
CallContext();
context.Company = "EAM";
StudentTableServiceClient proxy = new StudentTableServiceClient();
try
{
studentAxd = proxy.read(context, Program.readCritera(rollNumber));
//Console.WriteLine("Read worked");
Program.updateCustomer(studentAxd, rollNumber);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
private static EntityKey[] readCritera(int rollNumber)
{
StudentTableServiceClient client = new StudentTableServiceClient();
AxdStudentTable localAxd = new AxdStudentTable();
CriteriaElement[] criteriaElements = new CriteriaElement[1];
criteriaElements[0] = new CriteriaElement();
criteriaElements[0].DataSourceName = "StudentTable";
criteriaElements[0].FieldName = "RollNumber";
criteriaElements[0].Value1 = rollNumber.ToString();
QueryCriteria queryCriteria = new QueryCriteria();
queryCriteria.CriteriaElement = criteriaElements;
CallContext readContext = new
CallContext();
readContext.Company = "EAM";
//Using find operation
localAxd = client.find(readContext, queryCriteria);
//Using read operation
EntityKey[] entityKeyList = new EntityKey[1];
EntityKey key = new EntityKey();
KeyField[] keyFields = new KeyField[1];
KeyField keyField = new KeyField();
keyField.Field = "RecID";
keyField.Value = localAxd.StudentTable[0].RecId.ToString();
keyFields[0] = keyField;
key.KeyData = keyFields;
entityKeyList[0] = key;
return entityKeyList;
}
private static void updateCustomer(AxdStudentTable studentTableAxd, int rollNumber)
{
try
{
StudentTableServiceClient updateProxy = new StudentTableServiceClient();
CallContext updateContext = new CallContext();
updateContext.Company = "EAM";
AxdEntity_StudentTable OldStudentEntity = studentTableAxd.StudentTable[0];
AxdEntity_StudentTable newStudentEntity = new AxdEntity_StudentTable();
AxdStudentTable newStudentAxd = new AxdStudentTable();
newStudentAxd.ValidTimeStateType = studentTableAxd.ValidTimeStateType;
newStudentAxd.ValidTimeStateTypeSpecified = true;
newStudentAxd.ValidAsOfDateTime = studentTableAxd.ValidAsOfDateTime;
newStudentAxd.ValidFromDateTime = studentTableAxd.ValidFromDateTime;
newStudentAxd.ValidToDateTime = studentTableAxd.ValidToDateTime;
newStudentEntity._DocumentHash = OldStudentEntity._DocumentHash;
newStudentEntity.RecId = OldStudentEntity.RecId;
newStudentEntity.RecVersion = OldStudentEntity.RecVersion;
newStudentEntity.action = AxdEnum_AxdEntityAction.update;
newStudentEntity.actionSpecified = true;
newStudentEntity.Name = "Suresk kumar";
#region Update the date effective entities
newStudentEntity.DirPartyTable = OldStudentEntity.DirPartyTable;
newStudentEntity.DirPartyTable[0].action = AxdEnum_AxdEntityAction.update;
newStudentEntity.DirPartyTable[0].actionSpecified = true;
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].StreetNumber = "10";
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].Roles = "Home";
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].Street = "street updated 1223";
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].action = AxdEnum_AxdEntityAction.update;
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].actionSpecified = true;
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].updateMode = AxdEnum_ValidTimeStateUpdate.Correction;
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].updateModeSpecified = true;
newStudentEntity.DirPartyTable[0].DirPartyContactInfoView[0].Locator = "+61 (0) 12 345 678";
newStudentEntity.DirPartyTable[0].DirPartyContactInfoView[0].Roles = "Home";
newStudentEntity.DirPartyTable[0].DirPartyContactInfoView[0].Type = AxdEnum_LogisticsElectronicAddressMethodType.Phone;
newStudentEntity.DirPartyTable[0].DirPartyContactInfoView[0].action = AxdEnum_AxdEntityAction.update;
newStudentEntity.DirPartyTable[0].DirPartyContactInfoView[0].actionSpecified = true;
newStudentAxd.StudentTable = new AxdEntity_StudentTable[1] { newStudentEntity };
#endregion
updateProxy.update(updateContext, Program.readCritera(rollNumber), newStudentAxd);
Console.Write("Worked");
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("Failed");
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
}
}
In my second post of this series, I demonstrated the creation of document service for a new entity. The post also include the solution on how to add the related postal address using AIF document service.
In order to achieve this we have added calls to some standard API's in prepareForSaveDetailsExtended() method of our service class.
In this post I am sharing the code which can be used to test the update operation on student entity with address.
In order to update the surrogate key indexed entity, we need to use the find operation for finding the entity key, and then based on the found entity key we can do the read operation which will return the Axd class instance which can be updated as per the requirement. Below is the code which will demonstrate the same requirement.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestStudentService.ServiceReference1;//Added namespace o access service in below application
namespace TestStudentService
{
class Program
{
static void Main(string[] args)
{
int rollNumber = 4;
AxdStudentTable studentAxd = null;
CallContext context = new
CallContext();
context.Company = "EAM";
StudentTableServiceClient proxy = new StudentTableServiceClient();
try
{
studentAxd = proxy.read(context, Program.readCritera(rollNumber));
//Console.WriteLine("Read worked");
Program.updateCustomer(studentAxd, rollNumber);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
private static EntityKey[] readCritera(int rollNumber)
{
StudentTableServiceClient client = new StudentTableServiceClient();
AxdStudentTable localAxd = new AxdStudentTable();
CriteriaElement[] criteriaElements = new CriteriaElement[1];
criteriaElements[0] = new CriteriaElement();
criteriaElements[0].DataSourceName = "StudentTable";
criteriaElements[0].FieldName = "RollNumber";
criteriaElements[0].Value1 = rollNumber.ToString();
QueryCriteria queryCriteria = new QueryCriteria();
queryCriteria.CriteriaElement = criteriaElements;
CallContext readContext = new
CallContext();
readContext.Company = "EAM";
//Using find operation
localAxd = client.find(readContext, queryCriteria);
//Using read operation
EntityKey[] entityKeyList = new EntityKey[1];
EntityKey key = new EntityKey();
KeyField[] keyFields = new KeyField[1];
KeyField keyField = new KeyField();
keyField.Field = "RecID";
keyField.Value = localAxd.StudentTable[0].RecId.ToString();
keyFields[0] = keyField;
key.KeyData = keyFields;
entityKeyList[0] = key;
return entityKeyList;
}
private static void updateCustomer(AxdStudentTable studentTableAxd, int rollNumber)
{
try
{
StudentTableServiceClient updateProxy = new StudentTableServiceClient();
CallContext updateContext = new CallContext();
updateContext.Company = "EAM";
AxdEntity_StudentTable OldStudentEntity = studentTableAxd.StudentTable[0];
AxdEntity_StudentTable newStudentEntity = new AxdEntity_StudentTable();
AxdStudentTable newStudentAxd = new AxdStudentTable();
newStudentAxd.ValidTimeStateType = studentTableAxd.ValidTimeStateType;
newStudentAxd.ValidTimeStateTypeSpecified = true;
newStudentAxd.ValidAsOfDateTime = studentTableAxd.ValidAsOfDateTime;
newStudentAxd.ValidFromDateTime = studentTableAxd.ValidFromDateTime;
newStudentAxd.ValidToDateTime = studentTableAxd.ValidToDateTime;
newStudentEntity._DocumentHash = OldStudentEntity._DocumentHash;
newStudentEntity.RecId = OldStudentEntity.RecId;
newStudentEntity.RecVersion = OldStudentEntity.RecVersion;
newStudentEntity.action = AxdEnum_AxdEntityAction.update;
newStudentEntity.actionSpecified = true;
newStudentEntity.Name = "Suresk kumar";
#region Update the date effective entities
newStudentEntity.DirPartyTable = OldStudentEntity.DirPartyTable;
newStudentEntity.DirPartyTable[0].action = AxdEnum_AxdEntityAction.update;
newStudentEntity.DirPartyTable[0].actionSpecified = true;
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].StreetNumber = "10";
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].Roles = "Home";
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].Street = "street updated 1223";
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].action = AxdEnum_AxdEntityAction.update;
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].actionSpecified = true;
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].updateMode = AxdEnum_ValidTimeStateUpdate.Correction;
newStudentEntity.DirPartyTable[0].DirPartyPostalAddressView[0].updateModeSpecified = true;
newStudentEntity.DirPartyTable[0].DirPartyContactInfoView[0].Locator = "+61 (0) 12 345 678";
newStudentEntity.DirPartyTable[0].DirPartyContactInfoView[0].Roles = "Home";
newStudentEntity.DirPartyTable[0].DirPartyContactInfoView[0].Type = AxdEnum_LogisticsElectronicAddressMethodType.Phone;
newStudentEntity.DirPartyTable[0].DirPartyContactInfoView[0].action = AxdEnum_AxdEntityAction.update;
newStudentEntity.DirPartyTable[0].DirPartyContactInfoView[0].actionSpecified = true;
newStudentAxd.StudentTable = new AxdEntity_StudentTable[1] { newStudentEntity };
#endregion
updateProxy.update(updateContext, Program.readCritera(rollNumber), newStudentAxd);
Console.Write("Worked");
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("Failed");
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
}
}
In my next post I will demonstrate the use of methods of document service class which we can use for our customizations.
No comments:
Post a Comment