Signing a document version in a script

Consider a script which allows signing the current document version.

Script without using PublicAPI

Context variables are used in the script:
context.Document - variable of the Contract type
context.Director - variable of the User type

For the script to work, add the following assemblies:

Elewise.ELMA.Documents
Elewise.ELMA.Documents.Docflow

Namespaces:

using EleWise.ELMA.Documents;
using EleWise.ELMA.Documents.Managers;
using EleWise.ELMA.Documents.Models;
using EleWise.ELMA.Extensions;
using EleWise.ELMA.Model.Entities;
using EleWise.ELMA.Model.Services;
using FluentNHibernate.Conventions;
 
Script text:
var vers = DocumentVersionManager.Instance.Get(context.Document.Id).ToList(); //get all the document versions
foreach (var i in vers)
if (i.Status == DocumentVersionStatus.Current) //search for the current version
{
    var v_sign = DocumentVersionExtManager.Instance.Load(i.Id);
    var user = DocumentAssignUserManager.Instance.Create();
    user.User = context.Director;//specify the user who signs the document
    user.DocumentVersion = i;
    v_sign.SignedUsers.Add(user); //add the users who signed the document to the list
    context.Document.Save();
}
 
 
 
Creating a similar script with PublicAPI
Documentation on PublicAPI is available here

Context variables:

context.Director - variable of the User type
context.Document - variable of the Document type

Namespace:

using EleWise.ELMA.API;
 

Script text:

foreach (var vers in PublicAPI.Docflow.DocumentVersion.Filter().Document(context.Document).Status(PublicAPI.Enums.Documents.DocumentVersionStatus.Current).Find())
{
    var user = PublicAPI.Docflow.Objects.DocumentAssignUser.Create();
    user.User = context.Director;
    user.DocumentVersion = vers;
    vers.SignedUsers.Add(user);
    context.Document.Save();
}