PersonRepository.Create Method

Create new person.

Namespace: Gamanet.C4.SDK
Assembly: Gamanet.C4.SimpleClient (in Gamanet.C4.SimpleClient.dll) Version: 2026.0.0.733
Syntax
C#
public void Create(
	SimplePersonV1 person
)

Parameters

person  SimplePersonV1
The person.

Implements

ISimpleClientPersonRepositoryV1.Create(SimplePersonV1)
Example
The following example illustrates how to create group and assign person under
C#
using System;
using Gamanet.C4.SDK;
using Gamanet.C4.SimpleInterfaces;

public class Example
{
    static void Main()
    {
        // Create instance of simple client
        var client = new SimpleClient(ConnectorConfiguration.HttpClient);

        ConnectionInfoV1 token;
        // Connect to local server
        var connectionResult = client.Connect(new Uri("https://localhost/"), "Support", "support", out token);

        if (connectionResult != ConnectionResult.Successful)
        {
            Console.WriteLine("Connection unsuccessful, result: {0}", connectionResult);
            return;
        }

        Console.WriteLine("Connection result: {0}", connectionResult);
        Console.WriteLine();

        // create new instance of person
        var person = new SimplePersonV1(Guid.NewGuid(),
            EntityRoot.Person,
            PersonCategory.Person);
        person.Data["Surname"] = "Johnson"; // person's name

        // create person
        client.Persons.Create(person);

        // create new instance of simple person as new group
        var group = new SimplePersonV1(Guid.NewGuid(),
            EntityRoot.GroupRoot,
            PersonCategory.Group); // category group
        group.Data["Surname"] = "Group 1"; // name of group

        // create group
        client.Persons.Create(group);

        // create new instance of simple person as person reference
        var personReference = new SimplePersonV1(person.Id, // person's Id
            group.Id, // group's Id
            PersonCategory.PersonRef); // PersonRef category

        // assign person reference for group
        client.Persons.Create(personReference);

        // Get all person and references and print out their names
        var result = client.Persons.GetAll();
        foreach (var item in result)
        {
            Console.WriteLine(item.Name);
        }

        // Disconnect from server
        client.Disconnect();
    }
}
The following example illustrates how to create company and assign person under
C#
using System;
using Gamanet.C4.SDK;
using Gamanet.C4.SimpleInterfaces;

public class Example
{
    static void Main()
    {
        // Create instance of simple client
        var client = new SimpleClient(ConnectorConfiguration.HttpClient);

        ConnectionInfoV1 token;
        // Connect to local server
        var connectionResult = client.Connect(new Uri("https://localhost/"), "Support", "support", out token);

        if (connectionResult != ConnectionResult.Successful)
        {
            Console.WriteLine("Connection unsuccessful, result: {0}", connectionResult);
            return;
        }

        Console.WriteLine("Connection result: {0}", connectionResult);
        Console.WriteLine();

        // create new instance of simple person as new company
        var company = new SimplePersonV1(Guid.NewGuid(),
            EntityRoot.Person,
            PersonCategory.Company); // category company
        company.Data["Surname"] = "Company 1"; // name of company

        // create group
        client.Persons.Create(company);

        // create new instance of person
        var person = new SimplePersonV1(Guid.NewGuid(),
               company.Id, //person's parent Id is company Id
               PersonCategory.Person);
        person.Data["Surname"] = "Johnson"; // person's name

        // create person
        client.Persons.Create(person);

        // Get all persons
        var result = client.Persons.GetAll();
        foreach (var item in result)
        {
            Console.WriteLine(item.Name);
        }

        // Disconnect from server
        client.Disconnect();
    }
}
The following example illustrates how to create person reference and assign it under Role.
C#
using System;
using Gamanet.C4.SDK;
using Gamanet.C4.SimpleInterfaces;

public class Example
{
    static void Main()
    {
        // Create instance of simple client
        var client = new SimpleClient(ConnectorConfiguration.HttpClient);

        ConnectionInfoV1 token;
        // Connect to local server
        var connectionResult = client.Connect(new Uri("https://localhost/"), "Support", "support", out token);

        if (connectionResult != ConnectionResult.Successful)
        {
            Console.WriteLine("Connection unsuccessful, result: {0}", connectionResult);
            return;
        }

        Console.WriteLine("Connection result: {0}", connectionResult);
        Console.WriteLine();

        // create new instance of person
        var newPerson = new SimplePersonV1(Guid.NewGuid(),
            EntityRoot.Person,
            PersonCategory.Person);
        newPerson.Data["Surname"] = "Johnson"; // name of referenced person

        client.Persons.Create(newPerson);

        var what = client.Persons.Get(newPerson.Id, Properties.None);

        // create new instance of simple person
        var personReference = new SimplePersonV1(newPerson.Id, // person id
            roleId, // id of role
            PersonCategory.PersonRef);

        // create person reference under role
        client.Persons.Create(personReference);
        // in case you need to unassign a person from a role, remove person reference with Delete method

        // Get all persons
        var result = client.Persons.GetAll();
        foreach (var item in result)
        {
            Console.WriteLine(item.Name);
        }

        // Disconnect from server
        client.Disconnect();
    }
}
The following example illustrates how to create person tree
C#
using System;
using Gamanet.C4.SDK;
using Gamanet.C4.SimpleInterfaces;

public class Example
{
    static void Main()
    {
        // Create instance of simple client
        var client = new SimpleClient(ConnectorConfiguration.HttpClient);

        ConnectionInfoV1 token;
        // Connect to local server
        var connectionResult = client.Connect(new Uri("https://localhost/"), "Support", "support", out token);

        if (connectionResult != ConnectionResult.Successful)
        {
            Console.WriteLine("Connection unsuccessful, result: {0}", connectionResult);
            return;
        }

        Console.WriteLine("Connection result: {0}", connectionResult);
        Console.WriteLine();

        // create company under root
        var company = new SimplePersonV1(
            Guid.NewGuid(),
            EntityRoot.Person,
            PersonCategory.Company);
        company.Data["Surname"] = "Company";

        // create company
        client.Persons.Create(company);

        // create division under company
        var division = new SimplePersonV1(
            Guid.NewGuid(),
            company.Id,
            PersonCategory.Division);
        division.Data["Surname"] = "Division";

        // create division
        client.Persons.Create(division);

        // create department under division
        var department = new SimplePersonV1(
            Guid.NewGuid(),
            division.Id,
            PersonCategory.Department);
        department.Data["Surname"] = "Department";

        // create department
        client.Persons.Create(department);

        // create person under department
        var person = new SimplePersonV1(
            Guid.NewGuid(),
            department.Id,
            PersonCategory.Person);

        person.Data["Surname"] = "Johnson";

        // create person
        client.Persons.Create(person);

        // Get all persons
        var result = client.Persons.GetAll();
        foreach (var item in result)
        {
            Console.WriteLine(item.Name);
        }

        // Disconnect from server
        client.Disconnect();
    }
}
The following example illustrates how the SimpleClient Creates person.
C#
using System;
using Gamanet.C4.SDK;
using Gamanet.C4.SimpleInterfaces;

public class Example
{
    static void Main()
    {
        // Create instance of simple client
        var client = new SimpleClient(ConnectorConfiguration.HttpClient);

        ConnectionInfoV1 token;
        // Connect to local server
        var connectionResult = client.Connect(new Uri("https://localhost/"), "Support", "support", out token);

        if (connectionResult != ConnectionResult.Successful)
        {
            Console.WriteLine("Connection unsuccessful, result: {0}", connectionResult);
            return;
        }

        Console.WriteLine("Connection result: {0}", connectionResult);
        Console.WriteLine();

        // create new person under person root
        var newPerson = new SimplePersonV1(
            Guid.NewGuid(),
            EntityRoot.Person,
            PersonCategory.Person);
        newPerson.Data["Surname"] = "Smith"; //person surname is requried field

        // create person
        client.Persons.Create(newPerson);

        // Get all persons
        var result = client.Persons.GetAll();
        foreach (var item in result)
        {
            Console.WriteLine(item.Name);
        }

        // Disconnect from server
        client.Disconnect();
    }
}
See Also

Reference

PersonRepository Class
Gamanet.C4.SDK Namespace
SimplePersonV1
EntityRoot