diff --git a/EnvelopeGenerator.Application/EnvelopeGenerator.Application.csproj b/EnvelopeGenerator.Application/EnvelopeGenerator.Application.csproj
index 0406d46a..7f3ef53c 100644
--- a/EnvelopeGenerator.Application/EnvelopeGenerator.Application.csproj
+++ b/EnvelopeGenerator.Application/EnvelopeGenerator.Application.csproj
@@ -20,6 +20,7 @@
+
diff --git a/EnvelopeGenerator.Application/EnvelopeReceivers/Commands/Create/CreateEnvelopeReceiverCommand.cs b/EnvelopeGenerator.Application/EnvelopeReceivers/Commands/Create/CreateEnvelopeReceiverCommand.cs
index 7000950d..e9783a98 100644
--- a/EnvelopeGenerator.Application/EnvelopeReceivers/Commands/Create/CreateEnvelopeReceiverCommand.cs
+++ b/EnvelopeGenerator.Application/EnvelopeReceivers/Commands/Create/CreateEnvelopeReceiverCommand.cs
@@ -1,4 +1,5 @@
-using MediatR;
+using EnvelopeGenerator.Application.Envelopes.Commands;
+using MediatR;
using System.ComponentModel.DataAnnotations;
namespace EnvelopeGenerator.Application.EnvelopeReceivers.Commands.Create;
@@ -17,7 +18,7 @@ public record CreateEnvelopeReceiverCommand(
[Required] DocumentCreateCommand Document,
[Required] IEnumerable Receivers,
bool TFAEnabled = false
- ) : IRequest;
+ ) : CreateEnvelopeCommand(Title, Message, TFAEnabled), IRequest;
#region DTOs
///
diff --git a/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommand.cs b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommand.cs
new file mode 100644
index 00000000..147d6802
--- /dev/null
+++ b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommand.cs
@@ -0,0 +1,24 @@
+using MediatR;
+using System.ComponentModel.DataAnnotations;
+using System.Text.Json.Serialization;
+
+namespace EnvelopeGenerator.Application.Envelopes.Commands;
+
+///
+/// Befehl zur Erstellung eines Umschlags.
+///
+/// Der Titel des Umschlags. Dies ist ein Pflichtfeld.
+/// Die Nachricht, die im Umschlag enthalten sein soll. Dies ist ein Pflichtfeld.
+/// Gibt an, ob die Zwei-Faktor-Authentifizierung für den Umschlag aktiviert ist. Standardmäßig false.
+public record CreateEnvelopeCommand(
+ [Required] string Title,
+ [Required] string Message,
+ bool TFAEnabled = false
+ ) : IRequest
+{
+ ///
+ /// Id of receiver
+ ///
+ [JsonIgnore]
+ public int? UserId { get; set; }
+};
diff --git a/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommandHandler.cs b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommandHandler.cs
new file mode 100644
index 00000000..28801f45
--- /dev/null
+++ b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommandHandler.cs
@@ -0,0 +1,49 @@
+using AutoMapper;
+using EnvelopeGenerator.Application.Contracts.SQLExecutor;
+using EnvelopeGenerator.Domain.Entities;
+using MediatR;
+using Microsoft.Data.SqlClient;
+
+namespace EnvelopeGenerator.Application.Envelopes.Commands;
+
+///
+///
+///
+public class CreateEnvelopeCommandHandler : IRequestHandler
+{
+ private readonly ISQLExecutor _sqlExecutor;
+
+ private readonly IMapper _mapper;
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public CreateEnvelopeCommandHandler(ISQLExecutor sqlExecutor, IMapper mapper)
+ {
+ _sqlExecutor = sqlExecutor;
+ _mapper = mapper;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public async Task Handle(CreateEnvelopeCommand request, CancellationToken cancellationToken)
+ {
+ object[] parameters = new object[]
+ {
+ new SqlParameter("@UserId", request.UserId),
+ new SqlParameter("@Title", request.Title),
+ new SqlParameter("@TfaEnabled", request.TFAEnabled ? 1 : 0),
+ new SqlParameter("@Message", request.Message)
+ };
+
+ var envelope = await _sqlExecutor.Execute(cancellationToken, parameters).FirstOrDefaultAsync();
+
+ return _mapper.Map(envelope);
+ }
+}
diff --git a/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeResponse.cs b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeResponse.cs
new file mode 100644
index 00000000..805de24d
--- /dev/null
+++ b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeResponse.cs
@@ -0,0 +1,8 @@
+namespace EnvelopeGenerator.Application.Envelopes.Commands;
+
+///
+///
+///
+public class CreateEnvelopeResponse
+{
+}
diff --git a/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeSQL.cs b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeSQL.cs
index f07daffa..c3f2ebdd 100644
--- a/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeSQL.cs
+++ b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeSQL.cs
@@ -1,5 +1,6 @@
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
using EnvelopeGenerator.Domain.Entities;
+using Microsoft.Data.SqlClient;
namespace EnvelopeGenerator.Application.Envelopes.Commands;
///
@@ -10,5 +11,19 @@ public class CreateEnvelopeSQL : ISQL
///
///
///
- public string Raw => string.Empty;
+ public string Raw => @"
+ USE [DD_ECM];
+ DECLARE @OUT_UID varchar(36);
+
+ EXEC [dbo].[PRSIG_API_CREATE_ENVELOPE]
+ @USER_ID = @UserId,
+ @TITLE = @Title,
+ @TFAEnabled = @TfaEnabled,
+ @MESSAGE = @Message,
+ @OUT_UID = @OUT_UID OUTPUT;
+
+ SELECT *
+ FROM [dbo].[TBSIG_ENVELOPE]
+ WHERE [ENVELOPE_UUID] = @OUT_UID;
+ ";
}