diff --git a/ECMJobRunner.Application/ProfileHistories/Commands/CreateProfileHistoryCommand.cs b/ECMJobRunner.Application/ProfileHistories/Commands/CreateProfileHistoryCommand.cs new file mode 100644 index 0000000..5586834 --- /dev/null +++ b/ECMJobRunner.Application/ProfileHistories/Commands/CreateProfileHistoryCommand.cs @@ -0,0 +1,60 @@ +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 +{ + /// + /// Command to create a new profile execution history record + /// + public class CreateProfileHistoryCommand : IRequest + { + /// + /// Foreign key to the related profile + /// + public long ProfileId { get; set; } + + /// + /// Execution result type + /// + public ResultType Result { get; set; } + + /// + /// Result text/message + /// +#if NET + public required string ResultText { get; set; } +#else + + public string ResultText { get; set; } = null!; +#endif + + /// + /// Created by (max 50 chars) + /// + [JsonIgnore] + public string AddedWho { get; set; } = "ECMJobRunner"; + } + + /// + /// Handler for + /// + /// + /// Constructor + /// + public class CreateProfileHistoryCommandHandler(IProfileHistoryRepository Repository) : IRequestHandler + { + /// + /// Handles the command by persisting a new record + /// + public async Task Handle(CreateProfileHistoryCommand request, CancellationToken cancellationToken) + { + await Repository.AddAsync(request, cancellationToken); + return Unit.Value; + } + } +} diff --git a/ECMJobRunner.Application/ProfileHistories/MappingProfiles.cs b/ECMJobRunner.Application/ProfileHistories/MappingProfiles.cs new file mode 100644 index 0000000..4263191 --- /dev/null +++ b/ECMJobRunner.Application/ProfileHistories/MappingProfiles.cs @@ -0,0 +1,28 @@ +using ECMJobRunner.Application.ProfileHistories.Commands; +using ECMJobRunner.Domain.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ECMJobRunner.Application.ProfileHistories; + +/// +/// +/// +public class MappingProfiles : AutoMapper.Profile +{ + /// + /// + /// + public MappingProfiles() + { + CreateMap() + .ForMember(dest => dest.Id, opt => opt.Ignore()) + .ForMember(dest => dest.AddedWhen, opt => opt.MapFrom(_ => DateTime.Now)) + .ForMember(dest => dest.ChangedWho, opt => opt.Ignore()) + .ForMember(dest => dest.ChangedWhen, opt => opt.Ignore()) + .ForMember(dest => dest.CfgProfile, opt => opt.Ignore()); + } +}