Skip to main content
Let’s discuss how we can update the name, address, and position of an existing person using NetServer services. At the services layer, Person details can be updated only in one way: by using the PersonAgent and its SavePersonEntity method.

Code

CS

Walk-through

We need to use the GetPersonEntity method available in the PersonAgent to retrieve the PersonEntity that needs to be updated. Once the Entity is retrieved, the properties that are exposed can be updated. The example shows how we can update different types of properties exposed by the PersonEntity. Entity types consist of simple data types such as String, Boolean, DateTime, and int and complex data types consisting of types such as LocalizedFields and EntityElement types.

Updating simple data types

Simple data types can be updated with basic statements as shown below.
CS

Updating complex data types

However, complex data types cannot be modified in such a way. For example, if we need to update the Address property of the Person we need to first create a localized field array and store the new address in the declared variable. Only once this is done can it be assigned to the Address property of the PersonEntity.
CS
Another example of a complex type is properties, which are of entity element types. In the above example, we have created an EntityElement array and assigned values to the properties of the declared variable.
CS
Once the assignment is done, the created email can be added to Emails property of the PersonEntity by executing the statement below.
CS
The above would appear as a new email in the emails list of the Person. However, if we are required to modify an already existing email the goal could be archived as follows.
CS
Here we give the index of the Person’s Email location that needs to be changed.
CS
With the execution of the above statement, a value will be assigned to the Position property of the Person.
Position property uses pre-defined SuperOffice values, which are different from the title.
Once the required properties of the PersonEntity have been modified the modifications could be saved to the database with the execution of the below statement.
CS