Now able to setup assignments and they will start when the task is started.
This commit is contained in:
parent
1a064848ea
commit
fa7c2b1f64
@ -1,12 +1,13 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using e_suite.Database.Audit.Attributes;
|
||||
using e_suite.Database.Audit.Attributes;
|
||||
using e_suite.Database.Core.Models;
|
||||
using e_suite.Database.Core.Tables.Domain;
|
||||
using e_suite.Database.Core.Tables.UserManager;
|
||||
using eSuite.Core.Enums;
|
||||
using eSuite.Core.Workflow;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace e_suite.Database.Core.Tables.Activity;
|
||||
|
||||
@ -51,10 +52,11 @@ public class ActivityAssignment : IGeneralId, ISoftDeletable, IRuntimeOutcomes
|
||||
[ForeignKey(nameof(UserId))]
|
||||
public virtual User User { get; set; } = null!;
|
||||
|
||||
public List<string> Outcomes { get; set; }
|
||||
public List<string> Outcomes { get; set; } = [];
|
||||
public DateTimeOffset? StartDateTime { get; set; }
|
||||
public DateTimeOffset? FinishDateTime { get; set; }
|
||||
public string Comments { get; set; }
|
||||
public string Comments { get; set; } = string.Empty;
|
||||
public long? CompletedByUserId { get; set; }
|
||||
public string? CompletedByUserDisplayName { get; set; }
|
||||
public ActivityState ActivityState { get; set; } = ActivityState.Pending;
|
||||
}
|
||||
@ -53,7 +53,7 @@ public class ActivityTask : IGeneralId, ISoftDeletable, IRuntimeOutcomes
|
||||
/// </summary>
|
||||
public DateTimeOffset? FinishDateTime { get; set; }
|
||||
|
||||
public string Comments { get; set; }
|
||||
public string Comments { get; set; } = string.Empty;
|
||||
public long? CompletedByUserId { get; set; }
|
||||
public string? CompletedByUserDisplayName { get; set; }
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace esuite.Database.SqlServer.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddedActivityStatetotheassignmenttable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "ActivityState",
|
||||
schema: "Activity",
|
||||
table: "ActivityAssignments",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ActivityState",
|
||||
schema: "Activity",
|
||||
table: "ActivityAssignments");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -162,6 +162,9 @@ namespace esuite.Database.SqlServer.Migrations
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<int>("ActivityState")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("AllowNoVerdict")
|
||||
.HasColumnType("bit");
|
||||
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
using e_suite.Database.Core.Tables.Activity;
|
||||
using eSuite.Core.Enums;
|
||||
|
||||
namespace e_suite.Workflow.Core.Extensions;
|
||||
|
||||
public static class ActivityAssignmentExtensions
|
||||
{
|
||||
extension(ActivityAssignment task)
|
||||
{
|
||||
public void SetState(ActivityState newState)
|
||||
{
|
||||
if (newState == ActivityState.Active)
|
||||
{
|
||||
if (task.StartDateTime == null)
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot set state to Active because StartDateTime is not set for task {task.Id}."
|
||||
);
|
||||
}
|
||||
|
||||
if (newState == ActivityState.ReadyToComplete)
|
||||
{
|
||||
if (task.Outcomes == null || task.Outcomes.Count == 0)
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot set state to ReadyToComplete because no outcomes have been recorded for task {task.Id}."
|
||||
);
|
||||
}
|
||||
|
||||
if (newState == ActivityState.Completed)
|
||||
{
|
||||
if (task.FinishDateTime == null)
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot set state to Completed because FinishDateTime is not set for task {task.Id}."
|
||||
);
|
||||
}
|
||||
|
||||
task.ActivityState = newState;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -180,9 +180,16 @@ public static class TaskExtensions
|
||||
|
||||
public async Task StartTask(ActivityTask activityTask, IClock clock)
|
||||
{
|
||||
activityTask.StartDateTime = clock.GetNow;
|
||||
var now = clock.GetNow;
|
||||
activityTask.StartDateTime = now;
|
||||
activityTask.SetState(ActivityState.Active);
|
||||
|
||||
foreach (var assignment in activityTask.Assignments)
|
||||
{
|
||||
assignment.StartDateTime = now;
|
||||
assignment.SetState(ActivityState.Active);
|
||||
}
|
||||
|
||||
await task.OnStartedAsync(activityTask);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user