Files
ECMJobRunner/ECMJobRunner.Application/ProfileHistories/Commands/CreateProfileHistoryCommand.cs
TekH eb060aa54e Add CreateProfileHistoryCommand and mapping profiles
Introduce `CreateProfileHistoryCommand` to handle the creation of profile execution history records, including properties for `ProfileId`, `Result`, `ResultText`, and `AddedWho`.

Add `CreateProfileHistoryCommandHandler` to process the command and persist the data using `IProfileHistoryRepository`.

Define AutoMapper mappings in `MappingProfiles` to map `CreateProfileHistoryCommand` to the `ProfileHistory` entity, with specific configurations for ignored and mapped properties.
2026-08-03 12:08:54 +02:00

61 lines
1.7 KiB
C#

using ECMJobRunner.Domain.Entities;
using ECMJobRunner.Domain.Interfaces;
using ECMJobRunner.Domain.ValueObjects;
using MediatR;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
namespace ECMJobRunner.Application.ProfileHistories.Commands
{
/// <summary>
/// Command to create a new profile execution history record
/// </summary>
public class CreateProfileHistoryCommand : IRequest<Unit>
{
/// <summary>
/// Foreign key to the related profile
/// </summary>
public long ProfileId { get; set; }
/// <summary>
/// Execution result type
/// </summary>
public ResultType Result { get; set; }
/// <summary>
/// Result text/message
/// </summary>
#if NET
public required string ResultText { get; set; }
#else
public string ResultText { get; set; } = null!;
#endif
/// <summary>
/// Created by (max 50 chars)
/// </summary>
[JsonIgnore]
public string AddedWho { get; set; } = "ECMJobRunner";
}
/// <summary>
/// Handler for <see cref="CreateProfileHistoryCommand"/>
/// </summary>
/// <remarks>
/// Constructor
/// </remarks>
public class CreateProfileHistoryCommandHandler(IProfileHistoryRepository Repository) : IRequestHandler<CreateProfileHistoryCommand, Unit>
{
/// <summary>
/// Handles the command by persisting a new <see cref="ProfileHistory"/> record
/// </summary>
public async Task<Unit> Handle(CreateProfileHistoryCommand request, CancellationToken cancellationToken)
{
await Repository.AddAsync(request, cancellationToken);
return Unit.Value;
}
}
}