AssignmentUpdate#
An edit to one existing assignment of a live project. It goes in the Update list of SchedulingChanges.Assignments, which Project.Apply and Project.Preview take. Create it with new AssignmentUpdate(id) and set the fields to change in an object initializer.
Declaration#
namespace Plen;
public sealed class AssignmentUpdate : IDeepCloneable<AssignmentUpdate>
Constructors#
AssignmentUpdate(Id)#
public AssignmentUpdate(Id id)
Creates an update for the assignment with the given id. Every other property is Patch<T>.Missing, so the update changes nothing until a property is set.
| Name | Type | Description |
|---|---|---|
id |
Id |
Id of the assignment to edit. A string, int or double converts implicitly. |
Properties#
Every property except Id is a Patch<T>. Missing (the default) keeps the stored value, a value sets it, and Null clears it. The On Null column shows what Null does. For the meaning of each value, see the property of the same name on AssignmentData.
A plain value converts implicitly to a Patch<T>, so Value = 0.5 works. An Id property needs Patch<Id>.Of(...) when the value is a string or a number, because C# doesn't chain the two implicit conversions.
| Property | Type | On Null |
Description |
|---|---|---|---|
Id |
Id |
required | Id of the assignment to edit. |
Task |
Patch<Id> |
rejected | Moves the assignment to another task. |
Resource |
Patch<Id> |
rejected | Gives the assignment to another resource. |
Value |
Patch<double> |
rejected | New units booked. |
Offset |
Patch<double> |
null |
New start of the slice. null books from the task start. |
Duration |
Patch<double> |
null |
New length of the slice. null books up to the task end. |
The edited assignment must still meet the AssignmentData rules: Value and Duration greater than 0, Offset 0 or greater, and Task and Resource naming existing records.
Effect on dates#
Offset,DurationandValuechange resource load only. They never move a task.TaskandResourcemove dates only when the task then works on a different set of calendars, for example when the new resource has its own calendar inCalendarMode.Resource.- Moving an assignment to an unscheduled task keeps it in the project without booking load. Its id is listed in
ChangeEffects.DroppedAssignments.
Methods#
DeepClone#
public AssignmentUpdate DeepClone()
Returns a copy with the same property values.
Returns: a new AssignmentUpdate.
ToString#
public override string ToString()
Returns a debug dump of the fields, e.g. AssignmentUpdate { Id: a1, Task: Missing, Resource: Missing, … }.
Errors#
An update is rejected as a single operation, at path assignments.update[i]. Project.Apply and Project.Preview describe how a rejection is reported.
| Message | When it occurs |
|---|---|
unknown assignment id |
No assignment has Id. |
required field cannot be null |
Task, Resource or Value is Null. |
| a validation message | The edited assignment breaks an AssignmentData rule, for example an unknown Resource or a Value of 0. |
Example#
Hand Ben's review to Cara and narrow it to the last day of the task:
using Plen;
var start = Moment.FromYmdHm(2026, 4, 6, 8, 0)
?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
Tasks = [new TaskData(1) { StartDate = start, Duration = 5.0 }],
Resources =
[
new ResourceData { Id = "ben" },
new ResourceData { Id = "cara" },
],
Assignments =
[
new AssignmentData { Id = "review", Task = 1, Resource = "ben", Value = 0.5 },
],
};
var project = new Project();
project.Solve(data, new SolveOptions());
var changes = new SchedulingChanges();
changes.Assignments.Update.Add(new AssignmentUpdate("review")
{
Resource = Patch<Id>.Of("cara"),
Offset = 4.0,
Duration = 1.0,
});
var report = project.Apply(changes);
foreach (var rejected in report.Rejected)
{
Console.WriteLine($"{rejected.Path}: {rejected.Message}");
}
Related#
AssignmentData- the record being editedSchedulingChanges- the change set that carries the updatePatch<T>- the three-state field typeProject.Apply- commits the change set- Split assignment work - editing slices with updates