Creating a project in a script

This is an example of creating a project and project tasks using a script.

Script with PublicAPI

Note
Documentation on PublicAPI is available here
Attention
The script below is relevant for ELMA up to 3.12.1 inclusive.
var metadata = PublicAPI.Projects.Objects.ProjectMetadataHead.LoadOrNull(1); //ProjectWork type project metadata
var currentUser = PublicAPI.Portal.Security.User.GetCurrentUser(); //Current user
var project = PublicAPI.Projects.Project.Create("Project name", metadata, DateTime.Today, DateTime.Today.AddDays(30), currentUser);
 
var projectplan = PublicAPI.Projects.ProjectPlan.Filter().Project(project).Find().FirstOrDefault();
 
var projectTask = PublicAPI.Projects.ProjectTaskBase.ProjectTask.Create(project)
    .Subject("Task subject")
    .StartDate(DateTime.Today)
    .EndDate(DateTime.Today.AddDays(1))
    .Executor(currentUser)
    .AddToPlan(projectplan); //Creating a project task
var milestone = PublicAPI.Projects.ProjectTaskBase.Milestone.Create(project)
    .Subject("Milestone Subject")
    .StartDate(DateTime.Today)
    .Executor(currentUser)
    .AddToPlan(projectplan); //Creating a project milestone

Script without PublicAPI

Namespaces:
using EleWise.ELMA.Model.Services;
using EleWise.ELMA.Projects.Managers;
using EleWise.ELMA.Projects.Models;
using EleWise.ELMA.Security.Models;
using EleWise.ELMA.Security.Managers;
using EleWise.ELMA.Projects.Enums;​

Script text:
//Creating a project of the Project type
var project = InterfaceActivator.Create<ProjectWork>();
project.StartDate = DateTime.Today; //Project start date
project.FinishDate = DateTime.Today; //Project end date
project.Manager = (User)UserManager.Instance.LoadByLogin("admin"); //Project manager
project.Name = "Project name"; 
ProjectManager.Instance.SaveNew(project, true);
 
//Finding a project plan with the Draft status
var filter = InterfaceActivator.Create<ProjectPlanFilter>();
filter.Project = project;
filter.Status = ProjectPlanVersionStatus.Draft;
var projectplan = ProjectPlanManager.Instance.Find(filter, null).LastOrDefault();
  
//Creating a project task executor of the User type
var executor = InterfaceActivator.Create<ProjectTaskExecutor>();
executor.Type = ProjectTaskExecutorType.User; //User type
executor.User = (User)UserManager.Instance.LoadByLogin("admin");
executor.Save();
  
//Creating a simple project task
var PrjTask = InterfaceActivator.Create<ProjectPlanItem>();
PrjTask.ItemType = ProjectPlanItemType.ProjectTask; //Task type - project task
PrjTask.StartDate = DateTime.Today; //Start date - today
PrjTask.EndDate = DateTime.Today; //Due date - today
PrjTask.CreationAuthor = (User)UserManager.Instance.LoadByLogin("admin"); //Task author
PrjTask.Executor = executor; //Executor - (User) type, User
PrjTask.Subject = "Project task"; //Task name
PrjTask.ProjectPlan = projectplan; //Project plan
  
//Creating a milestone
var Milestone = InterfaceActivator.Create<ProjectPlanItem>();
Milestone.ItemType = ProjectPlanItemType.Milestone; //Task type - milestone
Milestone.StartDate = DateTime.Today; //Start date - today
Milestone.EndDate = DateTime.Today; //Due date - today
Milestone.CreationAuthor = (User)UserManager.Instance.LoadByLogin("admin"); //Task author
Milestone.Executor =  executor; //Executor - (User) type, User
Milestone.Subject = "Milestone"; //Task name
Milestone.ProjectPlan = projectplan; //Project plan