8 Commits

2342 changed files with 14856 additions and 23286 deletions

View File

@@ -1,19 +0,0 @@
namespace EnvelopeGenerator.Application.Configurations
{
public class AuthenticatorParams
{
public string CharPool { get; init; } = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789012345678901234567890123456789";
//TODO: Increase the DefaultTotpSecretKeyLength (e.g. to 32) but make sure that the QR code is generated correctly and can be scanned by the authenticator.
public int DefaultTotpSecretKeyLength { get; init; } = 20;
public string TotpIssuer { get; init; } = "signFlow";
/// <summary>
/// 0 is user email, 1 is secret key and 2 is issuer.
/// </summary>
public string TotpUrlFormat { get; init; } = "otpauth://totp/{0}?secret={1}&issuer={2}";
public int TotpQRPixelsPerModule { get; init; } = 20;
}
}

View File

@@ -1,5 +0,0 @@
namespace EnvelopeGenerator.Application.Configurations;
public class DbTriggerParams : Dictionary<string, IEnumerable<string>>
{
}

View File

@@ -0,0 +1,13 @@
namespace EnvelopeGenerator.Application.Configurations
{
public class DispatcherConfig
{
public int SendingProfile { get; init; } = 1;
public string AddedWho { get; init; } = "DDEnvelopGenerator";
public int ReminderTypeId { get; init; } = 202377;
public string EmailAttmt1 { get; init; } = string.Empty;
}
}

View File

@@ -1,12 +0,0 @@
namespace EnvelopeGenerator.Application.Configurations;
public class DispatcherParams
{
public int SendingProfile { get; init; } = 1;
public string AddedWho { get; init; } = "DDEnvelopGenerator";
public int ReminderTypeId { get; init; } = 202377;
public string EmailAttmt1 { get; init; } = string.Empty;
}

View File

@@ -1,20 +0,0 @@
using DigitalData.Core.Abstractions.Client;
namespace EnvelopeGenerator.Application.Configurations;
/// <summary>
/// https://www.gtx-messaging.com/en/api-docs/sms-rest-api/
/// </summary>
public class GtxMessagingParams : IHttpClientOptions
{
public required string Uri { get; init; }
public string? Path { get; init; }
public Dictionary<string, object>? Headers { get; init; }
public Dictionary<string, object?>? QueryParams { get; init; }
public string RecipientQueryParamName { get; init; } = "to";
public string MessageQueryParamName { get; init; } = "text";
}

View File

@@ -0,0 +1,7 @@
namespace EnvelopeGenerator.Application.Configurations
{
public class MailConfig
{
public required Dictionary<string, string> Placeholders { get; init; }
}
}

View File

@@ -1,6 +0,0 @@
namespace EnvelopeGenerator.Application.Configurations;
public class MailParams
{
public required Dictionary<string, string> Placeholders { get; init; }
}

View File

@@ -1,49 +0,0 @@
using OtpNet;
using System.Globalization;
namespace EnvelopeGenerator.Application.Configurations
{
public class TotpSmsParams
{
/// <summary>
/// The unit is second.
/// </summary>
public int TotpStep { get; init; } = 90;
public string Format { get; init; } = "Ihr 2FA-Passwort lautet {0}. Gültig bis {1}";
public ExpirationHandler Expiration { get; init; } = new();
public VerificationWindow? TotpVerificationWindow { get; private init; } = VerificationWindow.RfcSpecifiedNetworkDelay;
private IEnumerable<int>? _tvwParams;
public IEnumerable<int>? TotpVerificationWindowParams
{
get => _tvwParams;
init
{
_tvwParams = value;
if(_tvwParams is not null)
TotpVerificationWindow = new(previous: _tvwParams.ElementAtOrDefault(0), future: _tvwParams.ElementAtOrDefault(0));
}
}
public class ExpirationHandler
{
public string CacheKeyFormat { get; init; } = "e{0}_r{1}_sms_code_expiration";
public string Format { get; init; } = "HH:mm:ss";
public string CultureName
{
get => _cultureInfo.Name;
init => _cultureInfo = new(value);
}
private CultureInfo _cultureInfo = new("de-DE");
public CultureInfo CultureInfo => _cultureInfo;
}
}
}

View File

@@ -0,0 +1,17 @@
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IConfigService : IReadService<ConfigDto, Config, int>
{
Task<DataResult<ConfigDto>> ReadFirstAsync();
Task<ConfigDto> ReadDefaultAsync();
Task<string> ReadDefaultSignatureHost();
}
}

View File

@@ -0,0 +1,10 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IDocumentReceiverElementService : IBasicCRUDService<DocumentReceiverElementDto, DocumentReceiverElement, int>
{
}
}

View File

@@ -0,0 +1,9 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IDocumentStatusService : IBasicCRUDService<DocumentStatusDto, DocumentStatus, int>
{
}
}

View File

@@ -0,0 +1,13 @@
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IEmailTemplateService : IBasicCRUDService<EmailTemplateDto, EmailTemplate, int>
{
Task<DataResult<EmailTemplateDto>> ReadByNameAsync(EmailTemplateType type);
}
}

View File

@@ -0,0 +1,10 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IEnvelopeCertificateService : IBasicCRUDService<EnvelopeCertificateDto, EnvelopeCertificate, int>
{
}
}

View File

@@ -0,0 +1,10 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IEnvelopeDocumentService : IBasicCRUDService<EnvelopeDocumentDto, EnvelopeDocument, int>
{
}
}

View File

@@ -0,0 +1,28 @@
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs.EnvelopeHistory;
using EnvelopeGenerator.Application.DTOs.Receiver;
using EnvelopeGenerator.Domain.Entities;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IEnvelopeHistoryService : ICRUDService<EnvelopeHistoryCreateDto, EnvelopeHistoryDto, EnvelopeHistoryDto, EnvelopeHistory, long>
{
Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null);
Task<bool> AccessCodeAlreadyRequested(int envelopeId, string userReference);
Task<bool> IsSigned(int envelopeId, string userReference);
Task<bool> IsRejected(int envelopeId, string? userReference = null);
Task<IEnumerable<EnvelopeHistoryDto>> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, int? status = null, bool withSender = false, bool withReceiver = false);
Task<IEnumerable<EnvelopeHistoryDto>> ReadRejectedAsync(int envelopeId, string? userReference = null);
Task<IEnumerable<ReceiverReadDto>> ReadRejectingReceivers(int envelopeId);
Task<DataResult<long>> RecordAsync(int envelopeId, string userReference, EnvelopeStatus status, string? comment = null);
}
}

View File

@@ -0,0 +1,17 @@
using DigitalData.Core.DTO;
using DigitalData.EmailProfilerDispatcher.Abstraction.Contracts;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiverReadOnly;
using EnvelopeGenerator.Common;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IEnvelopeMailService : IEmailOutService
{
Task<DataResult<int>> SendAsync(EnvelopeReceiverDto envelopeReceiverDto, Constants.EmailTemplateType tempType);
Task<DataResult<int>> SendAsync(EnvelopeReceiverReadOnlyDto dto);
Task<DataResult<int>> SendAccessCodeAsync(EnvelopeReceiverDto envelopeReceiverDto);
}
}

View File

@@ -0,0 +1,10 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiverReadOnly;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IEnvelopeReceiverReadOnlyService : ICRUDService<EnvelopeReceiverReadOnlyCreateDto, EnvelopeReceiverReadOnlyDto, EnvelopeReceiverReadOnlyUpdateDto, EnvelopeReceiverReadOnly, long>
{
}
}

View File

@@ -0,0 +1,34 @@
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
using EnvelopeGenerator.Application.DTOs.Receiver;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IEnvelopeReceiverService : IBasicCRUDService<EnvelopeReceiverDto, EnvelopeReceiver, (int Envelope, int Receiver)>
{
Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false);
Task<DataResult<IEnumerable<EnvelopeReceiverSecretDto>>> ReadSecretByUuidAsync(string uuid, bool withEnvelope = false, bool withReceiver = true);
Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true);
Task<DataResult<EnvelopeReceiverDto>> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true);
Task<DataResult<EnvelopeReceiverDto>> ReadByEnvelopeReceiverIdAsync(string envelopeReceiverId, bool withEnvelope = true, bool withReceiver = true);
Task<DataResult<string>> ReadAccessCodeByIdAsync(int envelopeId, int receiverId);
Task<DataResult<bool>> VerifyAccessCodeAsync(string uuid, string signature, string accessCode);
Task<DataResult<bool>> VerifyAccessCodeAsync(string envelopeReceiverId, string accessCode);
Task<DataResult<bool>> IsExisting(string envelopeReceiverId);
Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadByUsernameAsync(string username, int? min_status = null, int? max_status = null, params int[] ignore_statuses);
Task<DataResult<string?>> ReadLastUsedReceiverNameByMail(string mail);
}
}

View File

@@ -0,0 +1,16 @@
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IEnvelopeService : IBasicCRUDService<EnvelopeDto, Envelope, int>
{
Task<DataResult<IEnumerable<EnvelopeDto>>> ReadAllWithAsync(bool documents = false, bool history = false, bool documentReceiverElement = false);
Task<DataResult<EnvelopeDto>> ReadByUuidAsync(string uuid, bool withDocuments = false, bool withHistory = false, bool withDocumentReceiverElement = false, bool withUser = false, bool withAll = false);
Task<DataResult<IEnumerable<EnvelopeDto>>> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[]ignore_statuses);
}
}

View File

@@ -0,0 +1,10 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IEnvelopeTypeService : IBasicCRUDService<EnvelopeTypeDto, EnvelopeType, int>
{
}
}

View File

@@ -0,0 +1,24 @@
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Security.Cryptography;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IJWTService<TClaimValue>
{
public static SymmetricSecurityKey GenerateSecurityKey(int byteSize = 32)
{
using var rng = RandomNumberGenerator.Create();
var randomBytes = new byte[byteSize];
rng.GetBytes(randomBytes);
var securityKey = new SymmetricSecurityKey(randomBytes);
return securityKey;
}
string GenerateToken(TClaimValue claimValue);
JwtSecurityToken? ReadSecurityToken(string token);
}
}

View File

@@ -0,0 +1,14 @@
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs.Receiver;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IReceiverService : ICRUDService<ReceiverCreateDto, ReceiverReadDto, ReceiverUpdateDto, Receiver, int>
{
public Task<DataResult<ReceiverReadDto>> ReadByAsync(string? emailAddress = null, string? signature = null);
public Task<Result> DeleteByAsync(string? emailAddress = null, string? signature = null);
}
}

View File

@@ -0,0 +1,10 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts
{
public interface IUserReceiverService : IBasicCRUDService<UserReceiverDto, UserReceiver, int>
{
}
}

View File

@@ -1,9 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Repositories;
public interface IConfigRepository : ICRUDRepository<Config, int>
{
Task<Config?> ReadFirstAsync();
}

View File

@@ -1,8 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Repositories;
public interface IDocumentReceiverElementRepository : ICRUDRepository<DocumentReceiverElement, int>
{
}

View File

@@ -1,8 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Repositories;
public interface IDocumentStatusRepository : ICRUDRepository<DocumentStatus, int>
{
}

View File

@@ -1,10 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using EnvelopeGenerator.Domain.Entities;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Application.Contracts.Repositories;
public interface IEmailTemplateRepository : ICRUDRepository<EmailTemplate, int>
{
Task<EmailTemplate?> ReadByNameAsync(EmailTemplateType type);
}

View File

@@ -1,8 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Repositories;
public interface IEnvelopeCertificateRepository : ICRUDRepository<EnvelopeCertificate, int>
{
}

View File

@@ -1,8 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Repositories;
public interface IEnvelopeDocumentRepository : ICRUDRepository<EnvelopeDocument, int>
{
}

View File

@@ -1,11 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Repositories;
public interface IEnvelopeHistoryRepository : ICRUDRepository<EnvelopeHistory, long>
{
Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null);
Task<IEnumerable<EnvelopeHistory>> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false);
}

View File

@@ -1,8 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Repositories;
public interface IEnvelopeReceiverReadOnlyRepository : ICRUDRepository<EnvelopeReceiverReadOnly, long>
{
}

View File

@@ -1,25 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Repositories;
public interface IEnvelopeReceiverRepository : ICRUDRepository<EnvelopeReceiver, (int Envelope, int Receiver)>
{
Task<IEnumerable<EnvelopeReceiver>> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false, bool readOnly = true);
Task<IEnumerable<EnvelopeReceiver>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true, bool readOnly = true);
Task<EnvelopeReceiver?> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true, bool readOnly = true);
Task<string?> ReadAccessCodeAsync(string uuid, string signature, bool readOnly = true);
Task<int> CountAsync(string uuid, string signature);
Task<EnvelopeReceiver?> ReadByIdAsync(int envelopeId, int receiverId, bool readOnly = true);
Task<string?> ReadAccessCodeByIdAsync(int envelopeId, int receiverId, bool readOnly = true);
Task<IEnumerable<EnvelopeReceiver>> ReadByUsernameAsync(string username, int? min_status = null, int? max_status = null, params int[] ignore_statuses);
Task<EnvelopeReceiver?> ReadLastByReceiver(string email);
}

View File

@@ -1,13 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Repositories;
public interface IEnvelopeRepository : ICRUDRepository<Envelope, int>
{
Task<IEnumerable<Envelope>> ReadAllWithAsync(bool documents = false, bool history = false, bool documentReceiverElement = false);
Task<Envelope?> ReadByUuidAsync(string uuid, bool withDocuments = false, bool withHistory = false, bool withDocumentReceiverElement = false, bool withUser = false, bool withAll = false);
Task<IEnumerable<Envelope>> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[] ignore_statuses);
}

View File

@@ -1,8 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Repositories;
public interface IEnvelopeTypeRepository : ICRUDRepository<EnvelopeType, int>
{
}

View File

@@ -1,9 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Repositories;
public interface IReceiverRepository : ICRUDRepository<Receiver, int>
{
Task<Receiver?> ReadByAsync(string? emailAddress = null, string? signature = null);
}

View File

@@ -1,8 +0,0 @@
using DigitalData.Core.Abstractions.Infrastructure;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Repositories;
public interface IUserReceiverRepository : ICRUDRepository<UserReceiver, int>
{
}

View File

@@ -1,18 +0,0 @@
using OtpNet;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IAuthenticator
{
string GenerateCode(int length);
string GenerateTotpSecretKey(int? length = null);
byte[] GenerateTotpQrCode(string userEmail, string secretKey, string? issuer = null, string? totpUrlFormat = null, int? pixelsPerModule = null);
byte[] GenerateTotpQrCode(string userEmail, int? length = null, string? issuer = null, string? totpUrlFormat = null, int? pixelsPerModule = null);
string GenerateTotp(string secretKey, int step = 30);
bool VerifyTotp(string totpCode, string secretKey, int step = 30, VerificationWindow? window = null);
}

View File

@@ -1,16 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IConfigService : IReadService<ConfigDto, Config, int>
{
Task<DataResult<ConfigDto>> ReadFirstAsync();
Task<ConfigDto> ReadDefaultAsync();
Task<string> ReadDefaultSignatureHost();
}

View File

@@ -1,9 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IDocumentReceiverElementService : IBasicCRUDService<DocumentReceiverElementDto, DocumentReceiverElement, int>
{
}

View File

@@ -1,8 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IDocumentStatusService : IBasicCRUDService<DocumentStatusDto, DocumentStatus, int>
{
}

View File

@@ -1,12 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IEmailTemplateService : IBasicCRUDService<EmailTemplateDto, EmailTemplate, int>
{
Task<DataResult<EmailTemplateDto>> ReadByNameAsync(EmailTemplateType type);
}

View File

@@ -1,9 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IEnvelopeCertificateService : IBasicCRUDService<EnvelopeCertificateDto, EnvelopeCertificate, int>
{
}

View File

@@ -1,9 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IEnvelopeDocumentService : IBasicCRUDService<EnvelopeDocumentDto, EnvelopeDocument, int>
{
}

View File

@@ -1,27 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs.EnvelopeHistory;
using EnvelopeGenerator.Application.DTOs.Receiver;
using EnvelopeGenerator.Domain.Entities;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IEnvelopeHistoryService : ICRUDService<EnvelopeHistoryCreateDto, EnvelopeHistoryDto, EnvelopeHistoryDto, EnvelopeHistory, long>
{
Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null);
Task<bool> AccessCodeAlreadyRequested(int envelopeId, string userReference);
Task<bool> IsSigned(int envelopeId, string userReference);
Task<bool> IsRejected(int envelopeId, string? userReference = null);
Task<IEnumerable<EnvelopeHistoryDto>> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, int? status = null, bool withSender = false, bool withReceiver = false);
Task<IEnumerable<EnvelopeHistoryDto>> ReadRejectedAsync(int envelopeId, string? userReference = null);
Task<IEnumerable<ReceiverReadDto>> ReadRejectingReceivers(int envelopeId);
Task<DataResult<long>> RecordAsync(int envelopeId, string userReference, EnvelopeStatus status, string? comment = null);
}

View File

@@ -1,18 +0,0 @@
using DigitalData.Core.DTO;
using DigitalData.EmailProfilerDispatcher.Abstraction.Contracts;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiverReadOnly;
using EnvelopeGenerator.Common;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IEnvelopeMailService : IEmailOutService
{
Task<DataResult<int>> SendAsync(EnvelopeReceiverDto envelopeReceiverDto, Constants.EmailTemplateType tempType, Dictionary<string, object>? optionalPlaceholders = null);
Task<DataResult<int>> SendAsync(EnvelopeReceiverReadOnlyDto dto, Dictionary<string, object>? optionalPlaceholders = null);
Task<DataResult<int>> SendAccessCodeAsync(EnvelopeReceiverDto envelopeReceiverDto);
Task<DataResult<int>> SendTFAQrCodeAsync(EnvelopeReceiverDto envelopeReceiverDto);
}

View File

@@ -1,9 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiverReadOnly;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IEnvelopeReceiverReadOnlyService : ICRUDService<EnvelopeReceiverReadOnlyCreateDto, EnvelopeReceiverReadOnlyDto, EnvelopeReceiverReadOnlyUpdateDto, EnvelopeReceiverReadOnly, long>
{
}

View File

@@ -1,37 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
using EnvelopeGenerator.Application.DTOs.Messaging;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IEnvelopeReceiverService : IBasicCRUDService<EnvelopeReceiverDto, EnvelopeReceiver, (int Envelope, int Receiver)>
{
Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false, bool readOnly = true);
Task<DataResult<IEnumerable<string?>>> ReadAccessCodeByUuidAsync(string uuid, bool withEnvelope = false, bool withReceiver = true);
Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true, bool readOnly = true);
Task<DataResult<EnvelopeReceiverDto>> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true, bool readOnly = true);
Task<DataResult<EnvelopeReceiverSecretDto>> ReadWithSecretByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true, bool readOnly = true);
Task<DataResult<EnvelopeReceiverDto>> ReadByEnvelopeReceiverIdAsync(string envelopeReceiverId, bool withEnvelope = true, bool withReceiver = true, bool readOnly = true);
Task<DataResult<string>> ReadAccessCodeByIdAsync(int envelopeId, int receiverId);
Task<DataResult<bool>> VerifyAccessCodeAsync(string uuid, string signature, string accessCode);
Task<DataResult<bool>> VerifyAccessCodeAsync(string envelopeReceiverId, string accessCode);
Task<DataResult<bool>> IsExisting(string envelopeReceiverId);
Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadByUsernameAsync(string username, int? min_status = null, int? max_status = null, params int[] ignore_statuses);
Task<DataResult<string?>> ReadLastUsedReceiverNameByMail(string mail);
Task<DataResult<SmsResponse>> SendSmsAsync(string envelopeReceiverId, string message);
}

View File

@@ -1,15 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IEnvelopeService : IBasicCRUDService<EnvelopeDto, Envelope, int>
{
Task<DataResult<IEnumerable<EnvelopeDto>>> ReadAllWithAsync(bool documents = false, bool history = false, bool documentReceiverElement = false);
Task<DataResult<EnvelopeDto>> ReadByUuidAsync(string uuid, bool withDocuments = false, bool withHistory = false, bool withDocumentReceiverElement = false, bool withUser = false, bool withAll = false);
Task<DataResult<IEnumerable<EnvelopeDto>>> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[] ignore_statuses);
}

View File

@@ -1,17 +0,0 @@
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
using EnvelopeGenerator.Application.DTOs.Messaging;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IEnvelopeSmsHandler
{
/// <summary>
/// If expiration is passed then, sends sms and returns smsResponse and up-to-date expiration; otherwise send expiration.
/// </summary>
/// <param name="er_secret"></param>
/// <param name="cToken"></param>
/// <returns></returns>
Task<(SmsResponse? SmsResponse, DateTime Expiration)> SendTotpAsync(EnvelopeReceiverSecretDto er_secret, CancellationToken cToken = default);
bool VerifyTotp(string totpCode, string secretKey);
}

View File

@@ -1,9 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IEnvelopeTypeService : IBasicCRUDService<EnvelopeTypeDto, EnvelopeType, int>
{
}

View File

@@ -1,16 +0,0 @@
using DigitalData.Core.Abstractions;
using DigitalData.Core.Abstractions.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs.Receiver;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IReceiverService : ICRUDService<ReceiverCreateDto, ReceiverReadDto, ReceiverUpdateDto, Receiver, int>
{
Task<DataResult<ReceiverReadDto>> ReadByAsync(string? emailAddress = null, string? signature = null);
Task<Result> DeleteByAsync(string? emailAddress = null, string? signature = null);
Task<Result> UpdateAsync<TUpdateDto>(TUpdateDto updateDto) where TUpdateDto : IUnique<int>;
}

View File

@@ -1,11 +0,0 @@
using EnvelopeGenerator.Application.DTOs.Messaging;
namespace EnvelopeGenerator.Application.Contracts.Services;
//TODO: move to DigitalData.Core
public interface ISmsSender
{
string ServiceProvider { get; }
Task<SmsResponse> SendSmsAsync(string recipient, string message);
}

View File

@@ -1,9 +0,0 @@
using DigitalData.Core.Abstractions.Application;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.Services;
public interface IUserReceiverService : IBasicCRUDService<UserReceiverDto, UserReceiver, int>
{
}

View File

@@ -0,0 +1,63 @@
using DigitalData.UserManager.Application.MappingProfiles;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.MappingProfiles;
using EnvelopeGenerator.Application.Configurations;
using EnvelopeGenerator.Application.Services;
using EnvelopeGenerator.Infrastructure.Contracts;
using EnvelopeGenerator.Infrastructure.Repositories;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace EnvelopeGenerator.Application
{
public static class DIExtensions
{
public static IServiceCollection AddEnvelopeGenerator(this IServiceCollection services, IConfiguration dispatcherConfigSection, IConfiguration mailConfigSection)
{
//Inject CRUD Service and repositoriesad
services.AddScoped<IConfigRepository, ConfigRepository>();
services.AddScoped<IDocumentReceiverElementRepository, DocumentReceiverElementRepository>();
services.AddScoped<IEnvelopeDocumentRepository, EnvelopeDocumentRepository>();
services.AddScoped<IConfigRepository, ConfigRepository>();
services.AddScoped<IDocumentReceiverElementRepository, DocumentReceiverElementRepository>();
services.AddScoped<IDocumentStatusRepository, DocumentStatusRepository>();
services.AddScoped<IEmailTemplateRepository, EmailTemplateRepository>();
services.AddScoped<IEnvelopeRepository, EnvelopeRepository>();
services.AddScoped<IEnvelopeCertificateRepository, EnvelopeCertificateRepository>();
services.AddScoped<IEnvelopeDocumentRepository, EnvelopeDocumentRepository>();
services.AddScoped<IEnvelopeHistoryRepository, EnvelopeHistoryRepository>();
services.AddScoped<IEnvelopeReceiverRepository, EnvelopeReceiverRepository>();
services.AddScoped<IEnvelopeTypeRepository, EnvelopeTypeRepository>();
services.AddScoped<IReceiverRepository, ReceiverRepository>();
services.AddScoped<IUserReceiverRepository, UserReceiverRepository>();
services.AddScoped<IEnvelopeReceiverReadOnlyRepository, EnvelopeReceiverReadOnlyRepository>();
services.AddScoped<IConfigService, ConfigService>();
services.AddScoped<IDocumentReceiverElementService, DocumentReceiverElementService>();
services.AddScoped<IEnvelopeDocumentService, EnvelopeDocumentService>();
services.AddScoped<IEnvelopeHistoryService, EnvelopeHistoryService>();
services.AddScoped<IDocumentStatusService, DocumentStatusService>();
services.AddScoped<IEmailTemplateService, EmailTemplateService>();
services.AddScoped<IEnvelopeService, EnvelopeService>();
services.AddScoped<IEnvelopeCertificateService, EnvelopeCertificateService>();
services.AddScoped<IEnvelopeDocumentService, EnvelopeDocumentService>();
services.AddScoped<IEnvelopeReceiverService, EnvelopeReceiverService>();
services.AddScoped<IEnvelopeTypeService, EnvelopeTypeService>();
services.AddScoped<IReceiverService, ReceiverService>();
services.AddScoped<IUserReceiverService, UserReceiverService>();
services.AddScoped<IEnvelopeReceiverReadOnlyService, EnvelopeReceiverReadOnlyService>();
//Auto mapping profiles
services.AddAutoMapper(typeof(BasicDtoMappingProfile).Assembly);
services.AddAutoMapper(typeof(UserMappingProfile).Assembly);
services.Configure<DispatcherConfig>(dispatcherConfigSection);
services.Configure<MailConfig>(mailConfigSection);
return services;
}
public static IServiceCollection AddEnvelopeGenerator(this IServiceCollection services, IConfiguration config) => services.AddEnvelopeGenerator(
dispatcherConfigSection: config.GetSection("DispatcherConfig"),
mailConfigSection: config.GetSection("MailConfig"));
}
}

View File

@@ -1,5 +1,4 @@
using DigitalData.Core.Abstractions;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
namespace EnvelopeGenerator.Application.DTOs
@@ -9,9 +8,11 @@ namespace EnvelopeGenerator.Application.DTOs
int SendingProfile,
string SignatureHost,
string ExternalProgramName,
string ExportPath) : IUnique<int>
string ExportPath,
string DocumentPathDmz,
string ExportPathDmz,
string DocumentPathMoveAftsend) : IUnique<int>
{
[NotMapped]
[JsonIgnore]
[Obsolete("Configuration does not have an ID; it represents a single table in the database.")]
public int Id => throw new InvalidOperationException("This configuration does not support an ID as it represents a single row in the database.");

View File

@@ -51,9 +51,7 @@ namespace EnvelopeGenerator.Application.DTOs
public int? ExpiresWarningWhenDays { get; set; }
public bool TFAEnabled { get; init; }
public bool DmzMoved { get; set; }
public bool DmzMoved { get; set; }
public UserReadDto? User { get; set; }
public EnvelopeType? EnvelopeType { get; set; }

View File

@@ -25,7 +25,5 @@ namespace EnvelopeGenerator.Application.DTOs.EnvelopeReceiver
public DateTime AddedWhen { get; init; }
public DateTime? ChangedWhen { get; init; }
public bool HasPhoneNumber { get; init; }
}
}

View File

@@ -1,9 +1,4 @@
namespace EnvelopeGenerator.Application.DTOs.EnvelopeReceiver
{
public record EnvelopeReceiverSecretDto() : EnvelopeReceiverDto()
{
public string? AccessCode { get; init; }
public string? PhoneNumber { get; init; }
}
public record EnvelopeReceiverSecretDto(string? AccessCode) : EnvelopeReceiverDto;
}

View File

@@ -1,4 +0,0 @@
namespace EnvelopeGenerator.Application.DTOs.Messaging
{
public class GtxMessagingResponse : Dictionary<string, object?> { }
}

View File

@@ -1,11 +0,0 @@
namespace EnvelopeGenerator.Application.DTOs.Messaging
{
public record SmsResponse
{
public required bool Ok { get; init; }
public bool Failed => !Ok;
public dynamic? Errors { get; init; }
}
}

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace EnvelopeGenerator.Application.DTOs.Receiver
{
public record ReceiverCreateDto([EmailAddress] string EmailAddress, string? TotpSecretkey = null)
public record ReceiverCreateDto([EmailAddress] string EmailAddress)
{
public string Signature => sha256HexOfMail.Value;

View File

@@ -1,24 +1,19 @@
using DigitalData.Core.Abstractions;
using DigitalData.Core.DTO;
using DigitalData.EmailProfilerDispatcher.Abstraction.Attributes;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
using System.Text.Json.Serialization;
namespace EnvelopeGenerator.Application.DTOs.Receiver;
public record ReceiverReadDto(
int Id,
string EmailAddress,
string Signature,
DateTime AddedWhen
) : BaseDTO<int>(Id), IUnique<int>
namespace EnvelopeGenerator.Application.DTOs.Receiver
{
[JsonIgnore]
public IEnumerable<EnvelopeReceiverBasicDto>? EnvelopeReceivers { get; init; }
public record ReceiverReadDto(
int Id,
string EmailAddress,
string Signature,
DateTime AddedWhen
) : BaseDTO<int>(Id)
{
[JsonIgnore]
public IEnumerable<EnvelopeReceiverBasicDto>? EnvelopeReceivers { get; init; }
public string? LastUsedName => EnvelopeReceivers?.LastOrDefault()?.Name;
public string? TotpSecretkey { get; set; } = null;
public DateTime? TfaRegDeadline { get; set; }
};
public string? LastUsedName => EnvelopeReceivers?.LastOrDefault()?.Name;
};
}

View File

@@ -1,5 +1,6 @@
using DigitalData.Core.Abstractions;
namespace EnvelopeGenerator.Application.DTOs.Receiver;
public record ReceiverUpdateDto(int Id, string? TotpSecretkey = null, DateTime? TfaRegDeadline = null) : IUnique<int>;
namespace EnvelopeGenerator.Application.DTOs.Receiver
{
public record ReceiverUpdateDto(int Id) : IUnique<int>;
}

View File

@@ -1,60 +1,56 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Remove="Resources\Model.Designer.vb" />
</ItemGroup>
<ItemGroup>
<None Remove="Resources\Model.Designer.vb" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="DigitalData.Core.Abstractions" Version="2.2.1" />
<PackageReference Include="DigitalData.Core.Application" Version="2.0.0" />
<PackageReference Include="DigitalData.Core.Client" Version="2.0.3" />
<PackageReference Include="DigitalData.Core.DTO" Version="2.0.0" />
<PackageReference Include="DigitalData.EmailProfilerDispatcher" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.18" />
<PackageReference Include="Otp.NET" Version="1.4.0" />
<PackageReference Include="QRCoder" Version="1.6.0" />
<PackageReference Include="QRCoder-ImageSharp" Version="0.10.0" />
<PackageReference Include="UserManager.Application" Version="2.0.0" />
<PackageReference Include="UserManager.Infrastructure" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="DigitalData.Core.Abstractions" Version="2.0.0" />
<PackageReference Include="DigitalData.Core.Application" Version="2.0.0" />
<PackageReference Include="DigitalData.Core.DTO" Version="2.0.0" />
<PackageReference Include="DigitalData.EmailProfilerDispatcher" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.18" />
<PackageReference Include="UserManager.Application" Version="2.0.0" />
<PackageReference Include="UserManager.Infrastructure" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EnvelopeGenerator.Domain\EnvelopeGenerator.Domain.csproj" />
<ProjectReference Include="..\EnvelopeGenerator.Extensions\EnvelopeGenerator.Extensions.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EnvelopeGenerator.Extensions\EnvelopeGenerator.Extensions.csproj" />
<ProjectReference Include="..\EnvelopeGenerator.Infrastructure\EnvelopeGenerator.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Resources\Model.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Model.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Update="Resources\Model.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Model.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\Model.en.resx">
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<LastGenOutput>Model.en.Designer.vb</LastGenOutput>
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Model.resx">
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<LastGenOutput>Model.Designer.cs</LastGenOutput>
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Resource.de-DE.resx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Resource.en-US.resx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\Model.en.resx">
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<LastGenOutput>Model.en.Designer.vb</LastGenOutput>
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Model.resx">
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<LastGenOutput>Model.Designer.cs</LastGenOutput>
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Resource.de-DE.resx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Resource.en-US.resx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@@ -1,131 +0,0 @@
using Microsoft.Extensions.Caching.Distributed;
namespace EnvelopeGenerator.Application.Extensions
{
public static class CacheExtensions
{
public static Task SetLongAsync(this IDistributedCache cache, string key, long value, DistributedCacheEntryOptions? options = null, CancellationToken cToken = default)
=> options is null
? cache.SetAsync(key, BitConverter.GetBytes(value), token: cToken)
: cache.SetAsync(key, BitConverter.GetBytes(value), options: options, token: cToken);
public static async Task<long?> GetLongAsync(this IDistributedCache cache, string key, CancellationToken cToken = default)
{
var value = await cache.GetAsync(key, cToken);
return value is null ? null : BitConverter.ToInt64(value, 0);
}
public static Task SetDateTimeAsync(this IDistributedCache cache, string key, DateTime value, DistributedCacheEntryOptions? options = null, CancellationToken cToken = default)
=> cache.SetLongAsync(key: key, value: value.Ticks, options: options, cToken: cToken);
public static async Task<DateTime?> GetDateTimeAsync(this IDistributedCache cache, string key, CancellationToken cToken = default)
{
var value = await cache.GetAsync(key, cToken);
return value is null ? null : new(BitConverter.ToInt64(value, 0));
}
public static Task SetTimeSpanAsync(this IDistributedCache cache, string key, TimeSpan value, DistributedCacheEntryOptions? options = null, CancellationToken cToken = default)
=> cache.SetLongAsync(key: key, value: value.Ticks, options: options, cToken);
public static async Task<TimeSpan?> GetTimeSpanAsync(this IDistributedCache cache, string key, CancellationToken cToken = default)
{
var value = await cache.GetAsync(key, cToken);
return value is null ? null : new(BitConverter.ToInt64(value, 0));
}
//TODO: use code generator
#region GetOrSetAsync
#region string
public static async Task<string> GetOrSetAsync(this IDistributedCache cache, string key, Func<string> factory, DistributedCacheEntryOptions? options = null, bool cacheInBackground = false, CancellationToken cToken = default)
{
var value = await cache.GetStringAsync(key, cToken);
if (value is null)
{
// create new and save
value = factory();
Task CacheAsync() => options is null
? cache.SetStringAsync(key, value, cToken)
: cache.SetStringAsync(key, value, options, cToken);
if (cacheInBackground)
_ = Task.Run(async () => await CacheAsync(), cToken);
else
await CacheAsync();
}
return value;
}
public static async Task<string> GetOrSetAsync(this IDistributedCache cache, string key, Func<Task<string>> factoryAsync, DistributedCacheEntryOptions? options = null, bool cacheInBackground = false, CancellationToken cToken = default)
{
var value = await cache.GetStringAsync(key, cToken);
if(value is null)
{
// create new and save
value = await factoryAsync();
Task CacheAsync() => options is null
? cache.SetStringAsync(key: key, value: value, token: cToken)
: cache.SetStringAsync(key: key, value: value, options: options, token: cToken);
if (cacheInBackground)
_ = Task.Run(async () => await CacheAsync(), cToken);
else
await CacheAsync();
}
return value;
}
#endregion
#region DateTime
public static async Task<DateTime> GetOrSetAsync(this IDistributedCache cache, string key, Func<DateTime> factory, DistributedCacheEntryOptions? options = null, bool cacheInBackground = false, CancellationToken cToken = default)
{
if (await cache.GetDateTimeAsync(key, cToken) is DateTime dateTimeValue)
return dateTimeValue;
else
{
// create new and save
var newValue = factory();
Task CacheAsync() => options is null
? cache.SetDateTimeAsync(key, newValue, cToken: cToken)
: cache.SetDateTimeAsync(key, newValue, options, cToken);
if (cacheInBackground)
_ = Task.Run(async () => await CacheAsync(), cToken);
else
await CacheAsync();
return newValue;
}
}
public static async Task<DateTime> GetOrSetAsync(this IDistributedCache cache, string key, Func<Task<DateTime>> factory, DistributedCacheEntryOptions? options = null, bool cacheInBackground = false, CancellationToken cToken = default)
{
if (await cache.GetDateTimeAsync(key, cToken) is DateTime dateTimeValue)
return dateTimeValue;
else
{
// create new and save
var newValue = await factory();
Task CacheAsync() => options is null
? cache.SetDateTimeAsync(key, newValue, cToken: cToken)
: cache.SetDateTimeAsync(key, newValue, options, cToken);
if (cacheInBackground)
_ = Task.Run(async () => await CacheAsync(), cToken);
else
await CacheAsync();
return newValue;
}
}
#endregion
#endregion
}
}

View File

@@ -1,52 +0,0 @@
using DigitalData.UserManager.Application.MappingProfiles;
using EnvelopeGenerator.Application.MappingProfiles;
using EnvelopeGenerator.Application.Configurations;
using EnvelopeGenerator.Application.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using DigitalData.Core.Client;
using QRCoder;
using EnvelopeGenerator.Application.Contracts.Services;
namespace EnvelopeGenerator.Application.Extensions;
public static class DIExtensions
{
public static IServiceCollection AddEnvelopeGeneratorServices(this IServiceCollection services, IConfiguration config)
{
//Inject CRUD Service and repositoriesad
services.TryAddScoped<IConfigService, ConfigService>();
services.TryAddScoped<IDocumentReceiverElementService, DocumentReceiverElementService>();
services.TryAddScoped<IEnvelopeDocumentService, EnvelopeDocumentService>();
services.TryAddScoped<IEnvelopeHistoryService, EnvelopeHistoryService>();
services.TryAddScoped<IDocumentStatusService, DocumentStatusService>();
services.TryAddScoped<IEmailTemplateService, EmailTemplateService>();
services.TryAddScoped<IEnvelopeService, EnvelopeService>();
services.TryAddScoped<IEnvelopeCertificateService, EnvelopeCertificateService>();
services.TryAddScoped<IEnvelopeDocumentService, EnvelopeDocumentService>();
services.TryAddScoped<IEnvelopeReceiverService, EnvelopeReceiverService>();
services.TryAddScoped<IEnvelopeTypeService, EnvelopeTypeService>();
services.TryAddScoped<IReceiverService, ReceiverService>();
services.TryAddScoped<IUserReceiverService, UserReceiverService>();
services.TryAddScoped<IEnvelopeReceiverReadOnlyService, EnvelopeReceiverReadOnlyService>();
//Auto mapping profiles
services.AddAutoMapper(typeof(BasicDtoMappingProfile).Assembly);
services.AddAutoMapper(typeof(UserMappingProfile).Assembly);
services.Configure<DispatcherParams>(config.GetSection(nameof(DispatcherParams)));
services.Configure<MailParams>(config.GetSection(nameof(MailParams)));
services.Configure<AuthenticatorParams>(config.GetSection(nameof(AuthenticatorParams)));
services.Configure<TotpSmsParams>(config.GetSection(nameof(TotpSmsParams)));
services.Configure<DbTriggerParams>(config.GetSection(nameof(DbTriggerParams)));
services.AddHttpClientService<GtxMessagingParams>(config.GetSection(nameof(GtxMessagingParams)));
services.TryAddSingleton<ISmsSender, GTXSmsSender>();
services.TryAddSingleton<IEnvelopeSmsHandler, EnvelopeSmsHandler>();
services.TryAddSingleton<IAuthenticator, Authenticator>();
services.TryAddSingleton<QRCodeGenerator>();
return services;
}
}

View File

@@ -1,14 +0,0 @@
using EnvelopeGenerator.Application.DTOs.Messaging;
namespace EnvelopeGenerator.Application.Extensions
{
public static class MappingExtensions
{
public static bool Ok(this GtxMessagingResponse gtxMessagingResponse)
=> gtxMessagingResponse.TryGetValue("message-status", out var status)
&& status?.ToString()?.ToLower() == "ok";
public static string ToBase64String(this byte[] bytes)
=> Convert.ToBase64String(bytes);
}
}

View File

@@ -14,7 +14,6 @@
public static readonly string PossibleSecurityBreach = nameof(PossibleSecurityBreach);
public static readonly string WrongEnvelopeReceiverId = nameof(WrongEnvelopeReceiverId);
public static readonly string EnvelopeOrReceiverNonexists = nameof(EnvelopeOrReceiverNonexists);
public static readonly string PhoneNumberNonexists = nameof(PhoneNumberNonexists);
public static readonly string Default = nameof(Default);
}
}

View File

@@ -3,9 +3,7 @@ using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Application.DTOs.EnvelopeHistory;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiverReadOnly;
using EnvelopeGenerator.Application.DTOs.Messaging;
using EnvelopeGenerator.Application.DTOs.Receiver;
using EnvelopeGenerator.Application.Extensions;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.MappingProfiles
@@ -45,20 +43,13 @@ namespace EnvelopeGenerator.Application.MappingProfiles
CreateMap<EnvelopeHistoryCreateDto, EnvelopeHistory>();
CreateMap<EnvelopeReceiverDto, EnvelopeReceiver>();
CreateMap<EnvelopeTypeDto, EnvelopeType>();
CreateMap<ReceiverReadDto, Receiver>().ForMember(rcv => rcv.EnvelopeReceivers, rcvReadDto => rcvReadDto.Ignore());
CreateMap<ReceiverReadDto, Receiver>();
CreateMap<ReceiverCreateDto, Receiver>();
CreateMap<ReceiverUpdateDto, Receiver>();
CreateMap<UserReceiverDto, UserReceiver>();
CreateMap<EnvelopeReceiverBase, EnvelopeReceiverBasicDto>();
CreateMap<EnvelopeReceiverReadOnlyCreateDto, EnvelopeReceiverReadOnly>();
CreateMap<EnvelopeReceiverReadOnlyUpdateDto, EnvelopeReceiverReadOnly>();
// Messaging mappings
// for GTX messaging
CreateMap<GtxMessagingResponse, SmsResponse>()
.ConstructUsing(gtxRes => gtxRes.Ok()
? new SmsResponse() { Ok = true }
: new SmsResponse() { Ok = false, Errors = gtxRes });
}
}
}

View File

@@ -156,63 +156,27 @@
<data name="Hello" xml:space="preserve">
<value>Hallo</value>
</data>
<data name="HomePageDescription" xml:space="preserve">
<value>Das digitale Unterschriftenportal ist eine Plattform, die entwickelt wurde, um Ihre Dokumente sicher zu unterschreiben und zu verwalten. Mit seiner benutzerfreundlichen Oberfläche können Sie Ihre Dokumente schnell hochladen, die Unterschriftsprozesse verfolgen und Ihre digitalen Unterschriftenanwendungen einfach durchführen. Dieses Portal beschleunigt Ihren Arbeitsablauf mit rechtlich gültigen Unterschriften und erhöht gleichzeitig die Sicherheit Ihrer Dokumente.</value>
<data name="LocakedOpen" xml:space="preserve">
<value>Öffnen</value>
</data>
<data name="LocationWarning" xml:space="preserve">
<value>Bitte überprüfen Sie die Standortinformationen. Wenn sie falsch sind, korrigieren Sie diese bitte.</value>
</data>
<data name="LockedBodyAccess" xml:space="preserve">
<value>Wir senden Ihnen nun einen Zugriffscode an Ihre hinterlegte Email-Adresse. Dies kann evtl. einige Minuten dauern!</value>
</data>
<data name="LockedBodyAuthenticator" xml:space="preserve">
<value>Bitte geben Sie den in Ihrer Authenticator-App angegebenen TOTP-Code ein.</value>
</data>
<data name="LockedBodyAuthenticatorNew" xml:space="preserve">
<value>Wir haben den QR-Code an Ihre E-Mail-Adresse gesendet. Ihr QR-Code ist bis {0} gültig. Sie können ihn für alle Umschläge verwenden, die Sie an diese E-Mail-Adresse erhalten.</value>
</data>
<data name="LockedBodySms" xml:space="preserve">
<value>Wir haben soeben den Zugangscode als SMS an die von Ihnen angegebene Telefonnummer gesendet.</value>
</data>
<data name="LockedCodeLabelAccess" xml:space="preserve">
<data name="LockedAccessCode" xml:space="preserve">
<value>Zugriffscode</value>
</data>
<data name="LockedCodeLabelAuthenticator" xml:space="preserve">
<value>TOTP</value>
<data name="LockedBody" xml:space="preserve">
<value>Wir haben Ihnen gerade den Zugriffscode an die hinterlegte Email Adresse gesendet. Dies kann evtl. einige Minuten dauern.</value>
</data>
<data name="LockedCodeLabelSms" xml:space="preserve">
<value>SMS-Code</value>
<data name="LockedFooterBody" xml:space="preserve">
<value>Bitte überprüfen Sie Ihr Email Postfach inklusive Spam-Ordner. Sie können auch den Absender bitten, Ihnen den Code auf anderem Wege zukommen zu lassen.</value>
</data>
<data name="LockedFooterBodyAccess" xml:space="preserve">
<value>Bitte überprüfen Sie Ihr Email Postfach inklusive Spam-Ordner. Sie können auch den Absender &lt;a class="mail-link" href="mailto:{0}?subject={1}&amp;body={2}" target="_blank"&gt;{0}&lt;/a&gt; bitten, Ihnen den Code auf anderem Wege zukommen zu lassen.</value>
</data>
<data name="LockedFooterBodyAuthenticator" xml:space="preserve">
<value>Der neue QR-Code wird nur einmal für einen bestimmten Zeitraum gesendet und nach dem Scannen in Ihrer Authenticator-App gespeichert. Er kann für alle Umschläge verwendet werden, die an dieselbe E-Mail-Adresse gesendet werden, bis er abläuft. Wenn Sie die QR-Code-Mail nicht erhalten oder sie sowohl aus der Mail als auch aus authenticator löschen, kontaktieren Sie bitte den Absender.</value>
</data>
<data name="LockedFooterBodySms" xml:space="preserve">
<value>Sie können den Absender bitten, Ihre Rufnummer zu überprüfen. Die Telefonnummer muss mit der Ortsvorwahl eingegeben werden. Andernfalls können Sie beantragen, den Zwei-Faktor-Schutz zu entfernen.</value>
</data>
<data name="LockedFooterTitleAccess" xml:space="preserve">
<data name="LockedFooterTitle" xml:space="preserve">
<value>Sie haben keinen Zugriffscode erhalten?</value>
</data>
<data name="LockedFooterTitleAuthenticator" xml:space="preserve">
<value>Sie haben keinen QR-Code erhalten?</value>
</data>
<data name="LockedFooterTitleSms" xml:space="preserve">
<value>Sie haben keine SMS erhalten?</value>
</data>
<data name="LockedTitleAccess" xml:space="preserve">
<data name="LockedTitle" xml:space="preserve">
<value>Dokument erfordert einen Zugriffscode</value>
</data>
<data name="LockedTitleAuthenticator" xml:space="preserve">
<value>2-Faktor-Authentifizierung</value>
</data>
<data name="LockedTitleSms" xml:space="preserve">
<value>2-Faktor-Authentifizierung</value>
</data>
<data name="Privacy" xml:space="preserve">
<value>Datenschutz</value>
</data>
<data name="ReadOnlyMessage" xml:space="preserve">
<value>Weitergeleitet von {0}. Gültig bis {1}.</value>
</data>

View File

@@ -156,63 +156,27 @@
<data name="Hello" xml:space="preserve">
<value>Hello</value>
</data>
<data name="HomePageDescription" xml:space="preserve">
<value>The Digital Signature Portal is a platform developed for securely signing and managing your documents. With its user-friendly interface, you can quickly upload your documents, track the signing processes, and easily carry out your digital signature applications. This portal accelerates your workflow with legally valid signatures while enhancing the security of your documents.</value>
<data name="LocakedOpen" xml:space="preserve">
<value>Open</value>
</data>
<data name="LocationWarning" xml:space="preserve">
<value>Please review the location information. If it is incorrect, kindly make the necessary corrections.</value>
</data>
<data name="LockedBodyAccess" xml:space="preserve">
<value>We will now send you an access code to your registered e-mail address. This may take a few minutes!</value>
</data>
<data name="LockedBodyAuthenticator" xml:space="preserve">
<value>Please enter the TOTP provided in your Authenticator app.</value>
</data>
<data name="LockedBodyAuthenticatorNew" xml:space="preserve">
<value>We have sent the QR code to your e-mail address. Your QR code is valid until {0}. You can use it for all envelopes received at this email address.</value>
</data>
<data name="LockedBodySms" xml:space="preserve">
<value>We have just sent the access code as an SMS to the phone number you provided.</value>
</data>
<data name="LockedCodeLabelAccess" xml:space="preserve">
<data name="LockedAccessCode" xml:space="preserve">
<value>Access Code</value>
</data>
<data name="LockedCodeLabelAuthenticator" xml:space="preserve">
<value>TOTP</value>
<data name="LockedBody" xml:space="preserve">
<value>We have just sent you the access code to the email address you provided. This may take a few minutes.</value>
</data>
<data name="LockedCodeLabelSms" xml:space="preserve">
<value>SMS Code</value>
<data name="LockedFooterBody" xml:space="preserve">
<value>Please check your email inbox including your spam folder. Furthermore, you can also ask the sender to send the code by other means.</value>
</data>
<data name="LockedFooterBodyAccess" xml:space="preserve">
<value>Please check your email inbox including the spam folder. You can also ask the sender &lt;a class="mail-link" href="mailto:{0}?subject={1}&amp;body={2}" target="_blank"&gt;{0}&lt;/a&gt; to send you the code by other means.</value>
</data>
<data name="LockedFooterBodyAuthenticator" xml:space="preserve">
<value>The new QR code is sent only once for a given period and is saved in your authenticator app once scanned. It can be used for all envelopes received at the same email address until it expires. If you do not receive the QR code mail or delete it both from the mail and from authenticator, please contact the sender.</value>
</data>
<data name="LockedFooterBodySms" xml:space="preserve">
<value>You can ask the sender to check your phone number. The phone number must be entered with the area code. Otherwise you can request to remove the two-factor protection.</value>
</data>
<data name="LockedFooterTitleAccess" xml:space="preserve">
<data name="LockedFooterTitle" xml:space="preserve">
<value>You have not received an access code?</value>
</data>
<data name="LockedFooterTitleAuthenticator" xml:space="preserve">
<value>You have not received a QR code?</value>
</data>
<data name="LockedFooterTitleSms" xml:space="preserve">
<value>You have not received an SMS?</value>
</data>
<data name="LockedTitleAccess" xml:space="preserve">
<data name="LockedTitle" xml:space="preserve">
<value>Document requires an access code</value>
</data>
<data name="LockedTitleAuthenticator" xml:space="preserve">
<value>2-Factor Authentication</value>
</data>
<data name="LockedTitleSms" xml:space="preserve">
<value>2-Factor Authentication</value>
</data>
<data name="Privacy" xml:space="preserve">
<value>Privacy</value>
</data>
<data name="ReadOnlyMessage" xml:space="preserve">
<value>Forwarded by {0}. Valid until {1}.</value>
</data>

View File

@@ -1,71 +0,0 @@
using EnvelopeGenerator.Application.Configurations;
using EnvelopeGenerator.Application.Contracts.Services;
using Microsoft.Extensions.Options;
using OtpNet;
using QRCoder;
using System.Text;
namespace EnvelopeGenerator.Application.Services
{
public class Authenticator : IAuthenticator
{
public static Lazy<Authenticator> LazyStatic => new(() => new Authenticator(Options.Create<AuthenticatorParams>(new()), new QRCodeGenerator()));
public static Authenticator Static => LazyStatic.Value;
private readonly AuthenticatorParams _params;
private readonly QRCodeGenerator _qrCodeGenerator;
public Authenticator(IOptions<AuthenticatorParams> options, QRCodeGenerator qrCodeGenerator)
{
_params = options.Value;
_qrCodeGenerator = qrCodeGenerator;
}
public string GenerateCode(int length)
{
//TODO: Inject Random as a singleton to support multithreading to improve performance.
Random random = new();
if (length <= 0)
throw new ArgumentException("Password length must be greater than 0.");
var passwordBuilder = new StringBuilder(length);
for (int i = 0; i < length; i++)
passwordBuilder.Append(_params.CharPool[random.Next(_params.CharPool.Length)]);
return passwordBuilder.ToString();
}
public string GenerateTotpSecretKey(int? length = null)
=> Base32Encoding.ToString(KeyGeneration.GenerateRandomKey(length ?? _params.DefaultTotpSecretKeyLength));
public byte[] GenerateTotpQrCode(string userEmail, string secretKey, string? issuer = null, string? totpUrlFormat = null, int? pixelsPerModule = null)
{
var url = string.Format(totpUrlFormat ?? _params.TotpUrlFormat,
Uri.EscapeDataString(userEmail),
Uri.EscapeDataString(secretKey),
Uri.EscapeDataString(issuer ?? _params.TotpIssuer));
using var qrCodeData = _qrCodeGenerator.CreateQrCode(url, QRCodeGenerator.ECCLevel.Q);
using var qrCode = new BitmapByteQRCode(qrCodeData);
return qrCode.GetGraphic(pixelsPerModule ?? _params.TotpQRPixelsPerModule);
}
public byte[] GenerateTotpQrCode(string userEmail, int? length = null, string? issuer = null, string? totpUrlFormat = null, int? pixelsPerModule = null)
{
return GenerateTotpQrCode(
userEmail: userEmail,
secretKey: GenerateTotpSecretKey(length: length),
issuer: issuer,
totpUrlFormat: totpUrlFormat,
pixelsPerModule: pixelsPerModule);
}
public string GenerateTotp(string secretKey, int step = 30) => new Totp(Base32Encoding.ToBytes(secretKey), step).ComputeTotp();
public bool VerifyTotp(string totpCode, string secretKey, int step = 30, VerificationWindow? window = null)
=> new Totp(Base32Encoding.ToBytes(secretKey), step).VerifyTotp(totpCode, out _, window);
}
}

View File

@@ -1,33 +1,33 @@
using AutoMapper;
using DigitalData.Core.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Infrastructure.Contracts;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
namespace EnvelopeGenerator.Application.Services;
public class ConfigService : ReadService<IConfigRepository, ConfigDto, Config, int>, IConfigService
namespace EnvelopeGenerator.Application.Services
{
public class ConfigService : ReadService<IConfigRepository, ConfigDto, Config, int>, IConfigService
{
private static readonly Guid DefaultConfigCacheId = Guid.NewGuid();
private readonly IMemoryCache _cache;
private readonly ILogger<ConfigService> _logger;
private readonly ILogger<ConfigService> _logger;
public ConfigService(IConfigRepository repository, IMapper mapper, IMemoryCache memoryCache, ILogger<ConfigService> logger) : base(repository, mapper)
{
{
_cache = memoryCache;
_logger = logger;
}
_logger = logger;
}
public async Task<DataResult<ConfigDto>> ReadFirstAsync()
{
var config = await _repository.ReadFirstAsync();
return config is null
? Result.Fail<ConfigDto>().Notice(LogLevel.Error, Flag.DataIntegrityIssue, "There is no configuration in DB.")
: Result.Success(_mapper.Map<ConfigDto>(config));
}
public async Task<DataResult<ConfigDto>> ReadFirstAsync()
{
var config = await _repository.ReadFirstAsync();
return config is null
? Result.Fail<ConfigDto>().Notice(LogLevel.Error, Flag.DataIntegrityIssue, "There is no configuration in DB.")
: Result.Success(_mapper.Map<ConfigDto>(config));
}
/// <summary>
/// Reads the default configuration asynchronously.
@@ -43,17 +43,18 @@ public class ConfigService : ReadService<IConfigRepository, ConfigDto, Config, i
/// Thrown when the default configuration cannot be found.
/// </exception>
public async Task<ConfigDto> ReadDefaultAsync()
{
var config = await _cache.GetOrCreateAsync(DefaultConfigCacheId, _ => ReadFirstAsync().ThenAsync(
Success: config => config,
Fail: (mssg, ntc) =>
{
_logger.LogNotice(ntc);
throw new InvalidOperationException("Default configuration cannot find.");
}));
{
var config = await _cache.GetOrCreateAsync(DefaultConfigCacheId, _ => ReadFirstAsync().ThenAsync(
Success: config => config,
Fail: (mssg, ntc) =>
{
_logger.LogNotice(ntc);
throw new InvalidOperationException("Default configuration cannot find.");
}));
return config!;
return config!;
}
public async Task<string> ReadDefaultSignatureHost() => (await ReadDefaultAsync()).SignatureHost;
}
public async Task<string> ReadDefaultSignatureHost() => (await ReadDefaultAsync()).SignatureHost;
}

View File

@@ -1,16 +1,17 @@
using AutoMapper;
using DigitalData.Core.Application;
using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Infrastructure.Contracts;
namespace EnvelopeGenerator.Application.Services;
public class DocumentReceiverElementService : BasicCRUDService<IDocumentReceiverElementRepository, DocumentReceiverElementDto, DocumentReceiverElement, int>, IDocumentReceiverElementService
namespace EnvelopeGenerator.Application.Services
{
public DocumentReceiverElementService(IDocumentReceiverElementRepository repository, IMapper mapper)
: base(repository, mapper)
public class DocumentReceiverElementService : BasicCRUDService<IDocumentReceiverElementRepository, DocumentReceiverElementDto, DocumentReceiverElement, int>, IDocumentReceiverElementService
{
public DocumentReceiverElementService(IDocumentReceiverElementRepository repository, IMapper mapper)
: base(repository, mapper)
{
}
}
}

View File

@@ -1,16 +1,17 @@
using AutoMapper;
using DigitalData.Core.Application;
using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Infrastructure.Contracts;
namespace EnvelopeGenerator.Application.Services;
public class DocumentStatusService : BasicCRUDService<IDocumentStatusRepository, DocumentStatusDto, DocumentStatus, int>, IDocumentStatusService
namespace EnvelopeGenerator.Application.Services
{
public DocumentStatusService(IDocumentStatusRepository repository, IMapper mapper)
: base(repository, mapper)
public class DocumentStatusService : BasicCRUDService<IDocumentStatusRepository, DocumentStatusDto, DocumentStatus, int>, IDocumentStatusService
{
public DocumentStatusService(IDocumentStatusRepository repository, IMapper mapper)
: base(repository, mapper)
{
}
}
}

View File

@@ -1,29 +1,30 @@
using AutoMapper;
using DigitalData.Core.Application;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Infrastructure.Contracts;
using static EnvelopeGenerator.Common.Constants;
using DigitalData.Core.DTO;
using Microsoft.Extensions.Logging;
using EnvelopeGenerator.Application.Contracts.Services;
namespace EnvelopeGenerator.Application.Services;
public class EmailTemplateService : BasicCRUDService<IEmailTemplateRepository, EmailTemplateDto, EmailTemplate, int>, IEmailTemplateService
namespace EnvelopeGenerator.Application.Services
{
public EmailTemplateService(IEmailTemplateRepository repository, IMapper mapper)
: base(repository, mapper)
public class EmailTemplateService : BasicCRUDService<IEmailTemplateRepository, EmailTemplateDto, EmailTemplate, int>, IEmailTemplateService
{
}
public EmailTemplateService(IEmailTemplateRepository repository, IMapper mapper)
: base(repository, mapper)
{
}
public async Task<DataResult<EmailTemplateDto>> ReadByNameAsync(EmailTemplateType type)
{
var temp = await _repository.ReadByNameAsync(type);
return temp is null
? Result.Fail<EmailTemplateDto>()
.Message(Key.InnerServiceError)
.Notice(LogLevel.Error, Flag.DataIntegrityIssue, $"EmailTemplateType '{type}' is not found in DB. Please, define required e-mail template.")
: Result.Success(_mapper.Map<EmailTemplateDto>(temp));
public async Task<DataResult<EmailTemplateDto>> ReadByNameAsync(EmailTemplateType type)
{
var temp = await _repository.ReadByNameAsync(type);
return temp is null
? Result.Fail<EmailTemplateDto>()
.Message(Key.InnerServiceError)
.Notice(LogLevel.Error, Flag.DataIntegrityIssue, $"EmailTemplateType '{type}' is not found in DB. Please, define required e-mail template.")
: Result.Success(_mapper.Map<EmailTemplateDto>(temp));
}
}
}

View File

@@ -1,17 +1,19 @@
using AutoMapper;
using DigitalData.Core.Application;
using Microsoft.Extensions.Localization;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.Infrastructure.Contracts;
using EnvelopeGenerator.Application.Resources;
namespace EnvelopeGenerator.Application.Services;
public class EnvelopeCertificateService : BasicCRUDService<IEnvelopeCertificateRepository, EnvelopeCertificateDto, EnvelopeCertificate, int>, IEnvelopeCertificateService
namespace EnvelopeGenerator.Application.Services
{
public EnvelopeCertificateService(IEnvelopeCertificateRepository repository, IMapper mapper)
: base(repository, mapper)
public class EnvelopeCertificateService : BasicCRUDService<IEnvelopeCertificateRepository, EnvelopeCertificateDto, EnvelopeCertificate, int>, IEnvelopeCertificateService
{
public EnvelopeCertificateService(IEnvelopeCertificateRepository repository, IMapper mapper)
: base(repository, mapper)
{
}
}
}

View File

@@ -1,15 +1,16 @@
using AutoMapper;
using DigitalData.Core.Application;
using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Infrastructure.Contracts;
namespace EnvelopeGenerator.Application.Services;
public class EnvelopeDocumentService : BasicCRUDService<IEnvelopeDocumentRepository, EnvelopeDocumentDto, EnvelopeDocument, int>, IEnvelopeDocumentService
namespace EnvelopeGenerator.Application.Services
{
public EnvelopeDocumentService(IEnvelopeDocumentRepository repository, IMapper mapper) : base(repository, mapper)
public class EnvelopeDocumentService : BasicCRUDService<IEnvelopeDocumentRepository, EnvelopeDocumentDto, EnvelopeDocument, int>, IEnvelopeDocumentService
{
public EnvelopeDocumentService(IEnvelopeDocumentRepository repository, IMapper mapper) : base(repository, mapper)
{
}
}
}

View File

@@ -1,84 +1,85 @@
using AutoMapper;
using DigitalData.Core.Application;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Infrastructure.Contracts;
using static EnvelopeGenerator.Common.Constants;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs.EnvelopeHistory;
using EnvelopeGenerator.Application.DTOs.Receiver;
using EnvelopeGenerator.Application.Contracts.Services;
namespace EnvelopeGenerator.Application.Services;
public class EnvelopeHistoryService : CRUDService<IEnvelopeHistoryRepository, EnvelopeHistoryCreateDto, EnvelopeHistoryDto, EnvelopeHistoryDto, EnvelopeHistory, long>, IEnvelopeHistoryService
namespace EnvelopeGenerator.Application.Services
{
public EnvelopeHistoryService(IEnvelopeHistoryRepository repository, IMapper mapper)
: base(repository, mapper)
public class EnvelopeHistoryService : CRUDService<IEnvelopeHistoryRepository, EnvelopeHistoryCreateDto, EnvelopeHistoryDto, EnvelopeHistoryDto, EnvelopeHistory, long>, IEnvelopeHistoryService
{
}
public EnvelopeHistoryService(IEnvelopeHistoryRepository repository, IMapper mapper)
: base(repository, mapper)
{
}
public async Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null) => await _repository.CountAsync(envelopeId: envelopeId, userReference: userReference, status: status);
public async Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null) => await _repository.CountAsync(envelopeId: envelopeId, userReference: userReference, status: status);
public async Task<bool> HasStatus(EnvelopeStatus status, int envelopeId, string userReference) => await _repository.CountAsync(
envelopeId: envelopeId,
userReference: userReference,
status: (int) status) > 0;
public async Task<bool> AccessCodeAlreadyRequested(int envelopeId, string userReference) => await _repository.CountAsync(
envelopeId: envelopeId,
userReference:userReference,
status: (int) EnvelopeStatus.AccessCodeRequested) > 0;
public async Task<bool> IsSigned(int envelopeId, string userReference) => await _repository.CountAsync(
envelopeId: envelopeId,
userReference: userReference,
status: (int) EnvelopeStatus.DocumentSigned) > 0;
/// <summary>
/// Checks if the specified envelope has been rejected.
/// <para><b>Note:</b> <i>If any document within the envelope is rejected, the entire envelope will be considered rejected.</i></para>
/// </summary>
/// <param name="envelopeId">The ID of the envelope to check.</param>
/// <param name="userReference">Optional user reference associated with the envelope.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the envelope is rejected.</returns>
public async Task<bool> IsRejected(int envelopeId, string? userReference = null)
{
return await _repository.CountAsync(
public async Task<bool> HasStatus(EnvelopeStatus status, int envelopeId, string userReference) => await _repository.CountAsync(
envelopeId: envelopeId,
userReference: userReference,
status: (int)EnvelopeStatus.DocumentRejected) > 0;
}
status: (int) status) > 0;
public async Task<IEnumerable<EnvelopeHistoryDto>> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, int? status = null, bool withSender = false, bool withReceiver = false)
{
var histDTOs = _mapper.Map<IEnumerable<EnvelopeHistoryDto>>(
await _repository.ReadAsync(
envelopeId: envelopeId,
userReference: userReference,
status: status,
withSender: withSender,
withReceiver: withReceiver));
return referenceType is null ? histDTOs : histDTOs.Where(h => h.ReferenceType == referenceType);
}
public async Task<bool> AccessCodeAlreadyRequested(int envelopeId, string userReference) => await _repository.CountAsync(
envelopeId: envelopeId,
userReference:userReference,
status: (int) EnvelopeStatus.AccessCodeRequested) > 0;
public async Task<IEnumerable<EnvelopeHistoryDto>> ReadRejectedAsync(int envelopeId, string? userReference = null) =>
await ReadAsync(envelopeId: envelopeId, userReference: userReference, status: (int)EnvelopeStatus.DocumentRejected, withReceiver:true);
public async Task<bool> IsSigned(int envelopeId, string userReference) => await _repository.CountAsync(
envelopeId: envelopeId,
userReference: userReference,
status: (int) EnvelopeStatus.DocumentSigned) > 0;
/// <summary>
/// Checks if the specified envelope has been rejected.
/// <para><b>Note:</b> <i>If any document within the envelope is rejected, the entire envelope will be considered rejected.</i></para>
/// </summary>
/// <param name="envelopeId">The ID of the envelope to check.</param>
/// <param name="userReference">Optional user reference associated with the envelope.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the envelope is rejected.</returns>
public async Task<bool> IsRejected(int envelopeId, string? userReference = null)
{
return await _repository.CountAsync(
envelopeId: envelopeId,
userReference: userReference,
status: (int)EnvelopeStatus.DocumentRejected) > 0;
}
public async Task<IEnumerable<EnvelopeHistoryDto>> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, int? status = null, bool withSender = false, bool withReceiver = false)
{
var histDTOs = _mapper.Map<IEnumerable<EnvelopeHistoryDto>>(
await _repository.ReadAsync(
envelopeId: envelopeId,
userReference: userReference,
status: status,
withSender: withSender,
withReceiver: withReceiver));
return referenceType is null ? histDTOs : histDTOs.Where(h => h.ReferenceType == referenceType);
}
public async Task<IEnumerable<EnvelopeHistoryDto>> ReadRejectedAsync(int envelopeId, string? userReference = null) =>
await ReadAsync(envelopeId: envelopeId, userReference: userReference, status: (int)EnvelopeStatus.DocumentRejected, withReceiver:true);
//TODO: use IQueryable in repository to incerease the performance
public async Task<IEnumerable<ReceiverReadDto>> ReadRejectingReceivers(int envelopeId)
{
var envelopes = await ReadRejectedAsync(envelopeId);
return envelopes is null
? Enumerable.Empty<ReceiverReadDto>()
: envelopes
.Where(eh => eh?.Receiver != null)
.Select(eh => eh.Receiver!);
return envelopes is null
? Enumerable.Empty<ReceiverReadDto>()
: envelopes
.Where(eh => eh?.Receiver != null)
.Select(eh => eh.Receiver!);
}
public async Task<DataResult<long>> RecordAsync(int envelopeId, string userReference, EnvelopeStatus status, string? comment = null) =>
await CreateAsync(new (EnvelopeId: envelopeId, UserReference: userReference, Status: (int)status, ActionDate: DateTime.Now, Comment: comment))
.ThenAsync(
Success: id => Result.Success(id),
Fail: (mssg, ntc) => Result.Fail<long>().Message(mssg).Notice(ntc)
);
await CreateAsync(new (EnvelopeId: envelopeId, UserReference: userReference, Status: (int)status, ActionDate: DateTime.Now, Comment: comment))
.ThenAsync(
Success: id => Result.Success(id),
Fail: (mssg, ntc) => Result.Fail<long>().Message(mssg).Notice(ntc)
);
}
}

View File

@@ -3,6 +3,7 @@ using DigitalData.Core.DTO;
using DigitalData.EmailProfilerDispatcher.Abstraction.Contracts;
using DigitalData.EmailProfilerDispatcher.Abstraction.DTOs.EmailOut;
using DigitalData.EmailProfilerDispatcher.Abstraction.Services;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
using EnvelopeGenerator.Common;
using Microsoft.Extensions.Logging;
@@ -11,9 +12,6 @@ using static EnvelopeGenerator.Common.Constants;
using EnvelopeGenerator.Extensions;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiverReadOnly;
using EnvelopeGenerator.Application.Configurations;
using EnvelopeGenerator.Application.Extensions;
using Newtonsoft.Json;
using EnvelopeGenerator.Application.Contracts.Services;
namespace EnvelopeGenerator.Application.Services
{
@@ -21,22 +19,20 @@ namespace EnvelopeGenerator.Application.Services
{
private readonly IEmailTemplateService _tempService;
private readonly IEnvelopeReceiverService _envRcvService;
private readonly DispatcherParams _dConfig;
private readonly DispatcherConfig _dConfig;
private readonly IConfigService _configService;
private readonly Dictionary<string, string> _placeholders;
private readonly IAuthenticator _authenticator;
public EnvelopeMailService(IEmailOutRepository repository, IMapper mapper, IEmailTemplateService tempService, IEnvelopeReceiverService envelopeReceiverService, IOptions<DispatcherParams> dispatcherConfigOptions, IConfigService configService, IOptions<MailParams> mailConfig, IAuthenticator authenticator) : base(repository, mapper)
public EnvelopeMailService(IEmailOutRepository repository, IMapper mapper, IEmailTemplateService tempService, IEnvelopeReceiverService envelopeReceiverService, IOptions<DispatcherConfig> dispatcherConfigOptions, IConfigService configService, IOptions<MailConfig> mailConfig) : base(repository, mapper)
{
_tempService = tempService;
_envRcvService = envelopeReceiverService;
_dConfig = dispatcherConfigOptions.Value;
_configService = configService;
_placeholders = mailConfig.Value.Placeholders;
_authenticator = authenticator;
}
private async Task<Dictionary<string, string>> CreatePlaceholders(string? accessCode = null, EnvelopeReceiverDto? envelopeReceiverDto = null)
private async Task<Dictionary<string, string>> CreatePlaceholders(string? accessCode = null, EnvelopeReceiverDto? envelopeReceiverDto = null, EnvelopeReceiverReadOnlyDto? readOnlyDto = null)
{
if (accessCode is not null)
_placeholders["[DOCUMENT_ACCESS_CODE]"] = accessCode;
@@ -67,8 +63,10 @@ namespace EnvelopeGenerator.Application.Services
return _placeholders;
}
public async Task<DataResult<int>> SendAsync(EnvelopeReceiverDto dto, EmailTemplateType tempType, Dictionary<string, object>? optionalPlaceholders = null)
public async Task<DataResult<int>> SendAccessCodeAsync(EnvelopeReceiverDto dto) => await SendAsync(dto: dto, tempType: Constants.EmailTemplateType.DocumentAccessCodeReceived);
public async Task<DataResult<int>> SendAsync(EnvelopeReceiverDto dto, Constants.EmailTemplateType tempType)
{
var tempSerResult = await _tempService.ReadByNameAsync(tempType);
if (tempSerResult.IsFailed)
@@ -106,19 +104,14 @@ namespace EnvelopeGenerator.Application.Services
var placeholders = await CreatePlaceholders(accessCode: accessCode, envelopeReceiverDto: dto);
// Add optional place holders.
if (optionalPlaceholders is not null)
foreach (var oph in optionalPlaceholders)
placeholders[oph.Key] = oph.Value.ToString() ?? "NULL";
//TODO: remove the requirement to add the models using reflections
return await CreateWithTemplateAsync(createDto: mail,placeholders: placeholders,
dto, dto.Envelope.User!, dto.Envelope);
}
public async Task<DataResult<int>> SendAsync(EnvelopeReceiverReadOnlyDto dto, Dictionary<string, object>? optionalPlaceholders = null)
public async Task<DataResult<int>> SendAsync(EnvelopeReceiverReadOnlyDto dto)
{
var tempSerResult = await _tempService.ReadByNameAsync(EmailTemplateType.DocumentShared);
var tempSerResult = await _tempService.ReadByNameAsync(Constants.EmailTemplateType.DocumentShared);
if (tempSerResult.IsFailed)
return tempSerResult.ToFail<int>().Notice(LogLevel.Error, Flag.DataIntegrityIssue, $"The email cannot send because '{Constants.EmailTemplateType.DocumentShared}' template cannot found.");
var temp = tempSerResult.Data;
@@ -147,29 +140,7 @@ namespace EnvelopeGenerator.Application.Services
var placeholders = await CreatePlaceholders(readOnlyDto: dto);
// Add optional place holders.
if (optionalPlaceholders is not null)
foreach (var oph in optionalPlaceholders)
placeholders[oph.Key] = oph.Value.ToString() ?? "NULL";
return await CreateWithTemplateAsync(createDto: mail, placeholders: placeholders, dto.Envelope);
}
public async Task<DataResult<int>> SendAccessCodeAsync(EnvelopeReceiverDto dto) => await SendAsync(dto: dto, tempType: EmailTemplateType.DocumentAccessCodeReceived);
public Task<DataResult<int>> SendTFAQrCodeAsync(EnvelopeReceiverDto dto)
{
// Check if receiver or secret key is null
if (dto.Receiver is null)
throw new ArgumentNullException(nameof(dto), $"TFA Qr Code cannot sent. Receiver information is missing. Envelope receiver dto is {JsonConvert.SerializeObject(dto)}");
if (dto.Receiver.TotpSecretkey is null)
throw new ArgumentNullException(nameof(dto), $"TFA Qr Code cannot sent. Receiver.TotpSecretKey is null. Envelope receiver dto is {JsonConvert.SerializeObject(dto)}");
var totp_qr_64 = _authenticator.GenerateTotpQrCode(userEmail: dto.Receiver.EmailAddress, secretKey: dto.Receiver.TotpSecretkey).ToBase64String();
return SendAsync(dto, EmailTemplateType.TotpSecret, new()
{
{"[TFA_QR_CODE]", totp_qr_64 },
});
}
}
}

View File

@@ -1,15 +1,16 @@
using AutoMapper;
using DigitalData.Core.Application;
using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiverReadOnly;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Infrastructure.Contracts;
namespace EnvelopeGenerator.Application.Services;
public class EnvelopeReceiverReadOnlyService : CRUDService<IEnvelopeReceiverReadOnlyRepository, EnvelopeReceiverReadOnlyCreateDto, EnvelopeReceiverReadOnlyDto, EnvelopeReceiverReadOnlyUpdateDto, EnvelopeReceiverReadOnly, long>, IEnvelopeReceiverReadOnlyService
namespace EnvelopeGenerator.Application.Services
{
public EnvelopeReceiverReadOnlyService(IEnvelopeReceiverReadOnlyRepository repository, IMapper mapper) : base(repository, mapper)
public class EnvelopeReceiverReadOnlyService : CRUDService<IEnvelopeReceiverReadOnlyRepository, EnvelopeReceiverReadOnlyCreateDto, EnvelopeReceiverReadOnlyDto, EnvelopeReceiverReadOnlyUpdateDto, EnvelopeReceiverReadOnly, long>, IEnvelopeReceiverReadOnlyService
{
public EnvelopeReceiverReadOnlyService(IEnvelopeReceiverReadOnlyRepository repository, IMapper mapper) : base(repository, mapper)
{
}
}
}

View File

@@ -1,178 +1,139 @@
using AutoMapper;
using DigitalData.Core.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
using EnvelopeGenerator.Application.Resources;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Infrastructure.Contracts;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using EnvelopeGenerator.Extensions;
using EnvelopeGenerator.Application.DTOs.Messaging;
using EnvelopeGenerator.Application.Contracts.Services;
namespace EnvelopeGenerator.Application.Services;
public class EnvelopeReceiverService : BasicCRUDService<IEnvelopeReceiverRepository, EnvelopeReceiverDto, EnvelopeReceiver, (int Envelope, int Receiver)>, IEnvelopeReceiverService
namespace EnvelopeGenerator.Application.Services
{
private readonly IStringLocalizer<Resource> _localizer;
private readonly ISmsSender _smsSender;
public EnvelopeReceiverService(IEnvelopeReceiverRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper, ISmsSender smsSender)
: base(repository, mapper)
public class EnvelopeReceiverService : BasicCRUDService<IEnvelopeReceiverRepository, EnvelopeReceiverDto, EnvelopeReceiver, (int Envelope, int Receiver)>, IEnvelopeReceiverService
{
_localizer = localizer;
_smsSender = smsSender;
}
private readonly IStringLocalizer<Resource> _localizer;
public async Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true, bool readOnly = true)
{
var env_rcvs = await _repository.ReadBySignatureAsync(signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly);
return Result.Success(_mapper.Map<IEnumerable<EnvelopeReceiverDto>>(env_rcvs));
}
public EnvelopeReceiverService(IEnvelopeReceiverRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper)
: base(repository, mapper)
{
_localizer = localizer;
}
public async Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false, bool readOnly = true)
{
var env_rcvs = await _repository.ReadByUuidAsync(uuid: uuid, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly);
return Result.Success(_mapper.Map<IEnumerable<EnvelopeReceiverDto>>(env_rcvs));
}
public async Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true)
{
var env_rcvs = await _repository.ReadBySignatureAsync(signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver);
return Result.Success(_mapper.Map<IEnumerable<EnvelopeReceiverDto>>(env_rcvs));
}
public async Task<DataResult<IEnumerable<string?>>> ReadAccessCodeByUuidAsync(string uuid, bool withEnvelope = false, bool withReceiver = true)
{
var env_rcvs = await _repository.ReadByUuidAsync(uuid: uuid, withEnvelope: withEnvelope, withReceiver: withReceiver);
return Result.Success(env_rcvs.Select(er => er.AccessCode));
}
public async Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false)
{
var env_rcvs = await _repository.ReadByUuidAsync(uuid: uuid, withEnvelope: withEnvelope, withReceiver: withReceiver);
return Result.Success(_mapper.Map<IEnumerable<EnvelopeReceiverDto>>(env_rcvs));
}
public async Task<DataResult<EnvelopeReceiverDto>> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true, bool readOnly = true)
{
var env_rcv = await _repository.ReadByUuidSignatureAsync(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly);
if (env_rcv is null)
return Result.Fail<EnvelopeReceiverDto>()
.Message(Key.EnvelopeReceiverNotFound);
public async Task<DataResult<IEnumerable<EnvelopeReceiverSecretDto>>> ReadSecretByUuidAsync(string uuid, bool withEnvelope = false, bool withReceiver = true)
{
var env_rcvs = await _repository.ReadByUuidAsync(uuid: uuid, withEnvelope: withEnvelope, withReceiver: withReceiver);
return Result.Success(_mapper.Map<IEnumerable<EnvelopeReceiverSecretDto>>(env_rcvs));
}
return Result.Success(_mapper.Map<EnvelopeReceiverDto>(env_rcv));
}
public async Task<DataResult<EnvelopeReceiverDto>> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true)
{
var env_rcv = await _repository.ReadByUuidSignatureAsync(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver);
if (env_rcv is null)
return Result.Fail<EnvelopeReceiverDto>()
.Message(Key.EnvelopeReceiverNotFound);
public async Task<DataResult<EnvelopeReceiverSecretDto>> ReadWithSecretByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true, bool readOnly = true)
{
var env_rcv = await _repository.ReadByUuidSignatureAsync(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly);
if (env_rcv is null)
return Result.Fail<EnvelopeReceiverSecretDto>()
.Message(Key.EnvelopeReceiverNotFound);
return Result.Success(_mapper.Map<EnvelopeReceiverDto>(env_rcv));
}
return Result.Success(_mapper.Map<EnvelopeReceiverSecretDto>(env_rcv));
}
public async Task<DataResult<EnvelopeReceiverDto>> ReadByEnvelopeReceiverIdAsync(string envelopeReceiverId, bool withEnvelope = true, bool withReceiver = true)
{
(string? uuid, string? signature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
public async Task<DataResult<EnvelopeReceiverDto>> ReadByEnvelopeReceiverIdAsync(string envelopeReceiverId, bool withEnvelope = true, bool withReceiver = true, bool readOnly = true)
{
(string? uuid, string? signature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
if (uuid is null || signature is null)
return Result.Fail<EnvelopeReceiverDto>()
.Message(_localizer[Key.WrongEnvelopeReceiverId])
.Notice(LogLevel.Warning, (uuid, signature).ToTitle())
.Notice(LogLevel.Warning, EnvelopeFlag.WrongEnvelopeReceiverId)
.Notice(LogLevel.Warning, Flag.PossibleSecurityBreach);
if (uuid is null || signature is null)
return Result.Fail<EnvelopeReceiverDto>()
.Message(_localizer[Key.WrongEnvelopeReceiverId])
.Notice(LogLevel.Warning, (uuid, signature).ToTitle())
.Notice(LogLevel.Warning, EnvelopeFlag.WrongEnvelopeReceiverId)
.Notice(LogLevel.Warning, Flag.PossibleSecurityBreach);
return await ReadByUuidSignatureAsync(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver);
}
return await ReadByUuidSignatureAsync(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly);
}
public async Task<DataResult<bool>> VerifyAccessCodeAsync(string uuid, string signature, string accessCode)
{
var er = await _repository.ReadByUuidSignatureAsync(uuid: uuid, signature: signature);
public async Task<DataResult<bool>> VerifyAccessCodeAsync(string uuid, string signature, string accessCode)
{
var er = await _repository.ReadByUuidSignatureAsync(uuid: uuid, signature: signature);
if (er is null)
return Result.Fail<bool>()
.Message(_localizer[Key.EnvelopeOrReceiverNonexists])
.Notice(LogLevel.Warning, (uuid, signature).ToTitle())
.Notice(LogLevel.Warning, EnvelopeFlag.EnvelopeOrReceiverNonexists)
.Notice(LogLevel.Warning, Flag.PossibleDataIntegrityIssue);
if (er is null)
return Result.Fail<bool>()
.Message(_localizer[Key.EnvelopeOrReceiverNonexists])
.Notice(LogLevel.Warning, (uuid, signature).ToTitle())
.Notice(LogLevel.Warning, EnvelopeFlag.EnvelopeOrReceiverNonexists)
.Notice(LogLevel.Warning, Flag.PossibleDataIntegrityIssue);
var actualAccessCode = er.AccessCode;
var actualAccessCode = er.AccessCode;
if (actualAccessCode is null)
return Result.Fail<bool>()
.Message(_localizer[Key.AccessCodeNull])
.Notice(LogLevel.Critical, (uuid, signature).ToTitle())
.Notice(LogLevel.Critical, EnvelopeFlag.AccessCodeNull)
.Notice(LogLevel.Critical, Flag.DataIntegrityIssue);
if (actualAccessCode is null)
return Result.Fail<bool>()
.Message(_localizer[Key.AccessCodeNull])
.Notice(LogLevel.Critical, (uuid, signature).ToTitle())
.Notice(LogLevel.Critical, EnvelopeFlag.AccessCodeNull)
.Notice(LogLevel.Critical, Flag.DataIntegrityIssue);
else if (accessCode != actualAccessCode)
return Result.Success(false).Message(_localizer[Key.WrongAccessCode]);
else
return Result.Success(true);
}
else if (accessCode != actualAccessCode)
return Result.Success(false).Message(_localizer[Key.WrongAccessCode]);
else
return Result.Success(true);
}
public async Task<DataResult<bool>> VerifyAccessCodeAsync(string envelopeReceiverId, string accessCode)
{
(string? uuid, string? signature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
public async Task<DataResult<bool>> VerifyAccessCodeAsync(string envelopeReceiverId, string accessCode)
{
(string? uuid, string? signature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
if (uuid is null || signature is null)
return Result.Fail<bool>()
.Message(Key.WrongEnvelopeReceiverId)
.Notice(LogLevel.Critical, EnvelopeFlag.WrongEnvelopeReceiverId)
.Notice(LogLevel.Critical, Flag.SecurityBreach)
.Notice(LogLevel.Critical, "Attempt to verify access code detected. Such actions are generally not initiated by well-intentioned users. Potential security breach suspected. Immediate investigation required.");
if (uuid is null || signature is null)
return Result.Fail<bool>()
.Message(Key.WrongEnvelopeReceiverId)
.Notice(LogLevel.Critical, EnvelopeFlag.WrongEnvelopeReceiverId)
.Notice(LogLevel.Critical, Flag.SecurityBreach)
.Notice(LogLevel.Critical, "Attempt to verify access code detected. Such actions are generally not initiated by well-intentioned users. Potential security breach suspected. Immediate investigation required.");
return await VerifyAccessCodeAsync(uuid: uuid, signature: signature, accessCode: accessCode);
}
return await VerifyAccessCodeAsync(uuid: uuid, signature: signature, accessCode: accessCode);
}
public async Task<DataResult<bool>> IsExisting(string envelopeReceiverId)
{
(string? uuid, string? signature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
public async Task<DataResult<bool>> IsExisting(string envelopeReceiverId)
{
(string? uuid, string? signature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
if (uuid is null || signature is null)
return Result.Fail<bool>().Notice(LogLevel.Warning, EnvelopeFlag.NonDecodableEnvelopeReceiverId, "In IsExisting(string envelopeReceiverId)");
if (uuid is null || signature is null)
return Result.Fail<bool>().Notice(LogLevel.Warning, EnvelopeFlag.NonDecodableEnvelopeReceiverId, "In IsExisting(string envelopeReceiverId)");
int count = await _repository.CountAsync(uuid:uuid, signature:signature);
return Result.Success(count > 0);
}
int count = await _repository.CountAsync(uuid:uuid, signature:signature);
return Result.Success(count > 0);
}
public async Task<DataResult<string>> ReadAccessCodeByIdAsync(int envelopeId, int receiverId)
{
var code = await _repository.ReadAccessCodeByIdAsync(envelopeId: envelopeId, receiverId: receiverId);
return code is null ?
Result.Fail<string>().Notice(LogLevel.Error, Flag.DataIntegrityIssue, $"Access code is null. Envelope ID is {envelopeId} and receiver ID {receiverId}")
: Result.Success(code);
var code = await _repository.ReadAccessCodeByIdAsync(envelopeId: envelopeId, receiverId: receiverId);
return code is null ?
Result.Fail<string>().Notice(LogLevel.Error, Flag.DataIntegrityIssue, $"Access code is null. Envelope ID is {envelopeId} and receiver ID {receiverId}")
: Result.Success(code);
}
public async Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadByUsernameAsync(string username, int? min_status = null, int? max_status = null, params int[] ignore_statuses)
{
var er_list = await _repository.ReadByUsernameAsync(username: username, min_status: min_status, max_status: max_status, ignore_statuses: ignore_statuses);
var dto_list = _mapper.Map<IEnumerable<EnvelopeReceiverDto>>(er_list);
return Result.Success(dto_list);
}
public async Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadByUsernameAsync(string username, int? min_status = null, int? max_status = null, params int[] ignore_statuses)
{
var er_list = await _repository.ReadByUsernameAsync(username: username, min_status: min_status, max_status: max_status, ignore_statuses: ignore_statuses);
var dto_list = _mapper.Map<IEnumerable<EnvelopeReceiverDto>>(er_list);
return Result.Success(dto_list);
}
public async Task<DataResult<string?>> ReadLastUsedReceiverNameByMail(string mail)
{
var er = await _repository.ReadLastByReceiver(mail);
return er is null ? Result.Fail<string?>().Notice(LogLevel.None, Flag.NotFound) : Result.Success(er.Name);
}
public async Task<DataResult<SmsResponse>> SendSmsAsync(string envelopeReceiverId, string message)
{
(string? uuid, string? signature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
if (uuid is null || signature is null)
return Result.Fail<SmsResponse>()
.Message(_localizer[Key.WrongEnvelopeReceiverId])
.Notice(LogLevel.Warning, (uuid, signature).ToTitle())
.Notice(LogLevel.Warning, EnvelopeFlag.WrongEnvelopeReceiverId)
.Notice(LogLevel.Warning, Flag.PossibleSecurityBreach);
var env_rcv = await _repository.ReadByUuidSignatureAsync(uuid: uuid, signature: signature, withEnvelope: false, withReceiver: false);
if (env_rcv is null)
return Result.Fail<SmsResponse>()
.Message(Key.EnvelopeReceiverNotFound);
if (env_rcv.PhoneNumber is null)
return Result.Fail<SmsResponse>()
.Message(Key.PhoneNumberNonexists)
.Notice(LogLevel.Error, Flag.NotFound, $"An attempt was made to send sms to the user whose phone number is null. Envelope recipient ID is {envelopeReceiverId}, UUID is {uuid} and signature is {signature}.");
var res = await _smsSender.SendSmsAsync(recipient: env_rcv.PhoneNumber, message: message);
return Result.Success(res);
public async Task<DataResult<string?>> ReadLastUsedReceiverNameByMail(string mail)
{
var er = await _repository.ReadLastByReceiver(mail);
return er is null ? Result.Fail<string?>().Notice(LogLevel.None, Flag.NotFound) : Result.Success(er.Name);
}
}
}

View File

@@ -1,42 +1,43 @@
using AutoMapper;
using DigitalData.Core.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Infrastructure.Contracts;
namespace EnvelopeGenerator.Application.Services;
public class EnvelopeService : BasicCRUDService<IEnvelopeRepository, EnvelopeDto, Envelope, int>, IEnvelopeService
namespace EnvelopeGenerator.Application.Services
{
public EnvelopeService(IEnvelopeRepository repository, IMapper mapper)
: base(repository, mapper)
public class EnvelopeService : BasicCRUDService<IEnvelopeRepository, EnvelopeDto, Envelope, int>, IEnvelopeService
{
}
public EnvelopeService(IEnvelopeRepository repository, IMapper mapper)
: base(repository, mapper)
{
}
public async Task<DataResult<IEnumerable<EnvelopeDto>>> ReadAllWithAsync(bool documents = false, bool history = false, bool documentReceiverElement = false)
{
var envelopes = await _repository.ReadAllWithAsync(documents: documents, history: history, documentReceiverElement: documentReceiverElement);
var readDto = _mapper.Map<IEnumerable<EnvelopeDto>>(envelopes);
return Result.Success(readDto);
}
public async Task<DataResult<IEnumerable<EnvelopeDto>>> ReadAllWithAsync(bool documents = false, bool history = false, bool documentReceiverElement = false)
{
var envelopes = await _repository.ReadAllWithAsync(documents: documents, history: history, documentReceiverElement: documentReceiverElement);
var readDto = _mapper.Map<IEnumerable<EnvelopeDto>>(envelopes);
return Result.Success(readDto);
}
public async Task<DataResult<EnvelopeDto>> ReadByUuidAsync(string uuid, bool withDocuments = false, bool withHistory = false, bool withDocumentReceiverElement = false, bool withUser = false, bool withAll = false)
{
var envelope = await _repository.ReadByUuidAsync(uuid: uuid, withDocuments: withDocuments, withHistory: withHistory, withDocumentReceiverElement: withDocumentReceiverElement, withUser:withUser, withAll:withAll);
public async Task<DataResult<EnvelopeDto>> ReadByUuidAsync(string uuid, bool withDocuments = false, bool withHistory = false, bool withDocumentReceiverElement = false, bool withUser = false, bool withAll = false)
{
var envelope = await _repository.ReadByUuidAsync(uuid: uuid, withDocuments: withDocuments, withHistory: withHistory, withDocumentReceiverElement: withDocumentReceiverElement, withUser:withUser, withAll:withAll);
if (envelope is null)
return Result.Fail<EnvelopeDto>();
if (envelope is null)
return Result.Fail<EnvelopeDto>();
var readDto = _mapper.Map<EnvelopeDto>(envelope);
return Result.Success(readDto);
}
var readDto = _mapper.Map<EnvelopeDto>(envelope);
return Result.Success(readDto);
}
public async Task<DataResult<IEnumerable<EnvelopeDto>>> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[] ignore_statuses)
{
var users = await _repository.ReadByUserAsync(userId: userId, min_status: min_status, max_status: max_status, ignore_statuses: ignore_statuses);
var readDto = _mapper.Map<IEnumerable<EnvelopeDto>>(users);
return Result.Success(readDto);
public async Task<DataResult<IEnumerable<EnvelopeDto>>> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[] ignore_statuses)
{
var users = await _repository.ReadByUserAsync(userId: userId, min_status: min_status, max_status: max_status, ignore_statuses: ignore_statuses);
var readDto = _mapper.Map<IEnumerable<EnvelopeDto>>(users);
return Result.Success(readDto);
}
}
}

View File

@@ -1,54 +0,0 @@
using EnvelopeGenerator.Application.Configurations;
using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
using EnvelopeGenerator.Application.DTOs.Messaging;
using EnvelopeGenerator.Application.Extensions;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;
namespace EnvelopeGenerator.Application.Services;
public class EnvelopeSmsHandler : IEnvelopeSmsHandler
{
private readonly ISmsSender _sender;
private readonly TotpSmsParams _totpSmsParams;
private readonly IDistributedCache _dCache;
private readonly IAuthenticator _authenticator;
public EnvelopeSmsHandler(ISmsSender sender, IOptions<TotpSmsParams> totpSmsParamsOptions, IDistributedCache distributedCache, IAuthenticator authenticator)
{
_sender = sender;
_totpSmsParams = totpSmsParamsOptions.Value;
_dCache = distributedCache;
_authenticator = authenticator;
}
/// <summary>
/// If expiration is passed then, sends sms and returns smsResponse and up-to-date expiration; otherwise send expiration.
/// </summary>
/// <param name="er_secret"></param>
/// <param name="cToken"></param>
/// <returns></returns>
public async Task<(SmsResponse? SmsResponse, DateTime Expiration)> SendTotpAsync(EnvelopeReceiverSecretDto er_secret, CancellationToken cToken = default)
{
var key = string.Format(_totpSmsParams.Expiration.CacheKeyFormat, er_secret.EnvelopeId, er_secret.ReceiverId);
var expiration = await _dCache.GetDateTimeAsync(key, cToken);
if(expiration is DateTime expirationDateTime && expirationDateTime >= DateTime.Now)
return (null, expirationDateTime);
else
{
var new_expiration = DateTime.Now.AddSeconds(_totpSmsParams.TotpStep);
var totp = _authenticator.GenerateTotp(er_secret.Receiver!.TotpSecretkey!, _totpSmsParams.TotpStep);
var msg = string.Format(_totpSmsParams.Format, totp, new_expiration.ToString(_totpSmsParams.Expiration.Format, _totpSmsParams.Expiration.CultureInfo));
await _dCache.SetDateTimeAsync(key, new_expiration, cToken: cToken);
return (await _sender.SendSmsAsync(er_secret.PhoneNumber!, msg), new_expiration);
}
}
public bool VerifyTotp(string totpCode, string secretKey) => _authenticator
.VerifyTotp(totpCode, secretKey, _totpSmsParams.TotpStep, _totpSmsParams.TotpVerificationWindow);
}

View File

@@ -1,29 +1,30 @@
using AutoMapper;
using DigitalData.Core.Application;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Infrastructure.Contracts;
using Microsoft.Extensions.Caching.Memory;
using DigitalData.Core.DTO;
using Microsoft.Extensions.Logging;
using EnvelopeGenerator.Application.Contracts.Services;
namespace EnvelopeGenerator.Application.Services;
public class EnvelopeTypeService : BasicCRUDService<IEnvelopeTypeRepository, EnvelopeTypeDto, EnvelopeType, int>, IEnvelopeTypeService
namespace EnvelopeGenerator.Application.Services
{
private static readonly Guid CacheKey = Guid.NewGuid();
private readonly IMemoryCache _cache;
public EnvelopeTypeService(IEnvelopeTypeRepository repository, IMapper mapper, IMemoryCache cache)
: base(repository, mapper)
public class EnvelopeTypeService : BasicCRUDService<IEnvelopeTypeRepository, EnvelopeTypeDto, EnvelopeType, int>, IEnvelopeTypeService
{
_cache = cache;
}
private static readonly Guid CacheKey = Guid.NewGuid();
public override async Task<DataResult<IEnumerable<EnvelopeTypeDto>>> ReadAllAsync()
=> await _cache.GetOrCreateAsync(CacheKey, async entry => await base.ReadAllAsync())
?? Result.Fail<IEnumerable<EnvelopeTypeDto>>().Notice(LogLevel.Error, Flag.NotFound, "No cached envelope types are available in the database. If you have added any envelope types after the server started, please restart the server.");
private readonly IMemoryCache _cache;
public EnvelopeTypeService(IEnvelopeTypeRepository repository, IMapper mapper, IMemoryCache cache)
: base(repository, mapper)
{
_cache = cache;
}
public override async Task<DataResult<IEnumerable<EnvelopeTypeDto>>> ReadAllAsync()
=> await _cache.GetOrCreateAsync(CacheKey, async entry => await base.ReadAllAsync())
?? Result.Fail<IEnumerable<EnvelopeTypeDto>>().Notice(LogLevel.Error, Flag.NotFound, "No cached envelope types are available in the database. If you have added any envelope types after the server started, please restart the server.");
}
}

View File

@@ -1,40 +0,0 @@
using AutoMapper;
using DigitalData.Core.Abstractions.Client;
using DigitalData.Core.Client;
using EnvelopeGenerator.Application.Configurations;
using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.Application.DTOs.Messaging;
using Microsoft.Extensions.Options;
namespace EnvelopeGenerator.Application.Services;
//TODO: move to DigitalData.Core
public class GTXSmsSender : ISmsSender
{
private readonly IHttpClientService<GtxMessagingParams> _smsClient;
private readonly GtxMessagingParams _smsParams;
private readonly IMapper _mapper;
public string ServiceProvider { get; }
public GTXSmsSender(IHttpClientService<GtxMessagingParams> smsClient, IOptions<GtxMessagingParams> smsParamsOptions, IMapper mapper)
{
_smsClient = smsClient;
_smsParams = smsParamsOptions.Value;
_mapper = mapper;
ServiceProvider = GetType().Name.Replace("Service", string.Empty);
}
public async Task<SmsResponse> SendSmsAsync(string recipient, string message)
{
return await _smsClient.FetchAsync(queryParams: new Dictionary<string, object?>()
{
{ _smsParams.RecipientQueryParamName, recipient },
{ _smsParams.MessageQueryParamName, message }
})
.ThenAsync(res => res.Json<GtxMessagingResponse>())
.ThenAsync(_mapper.Map<SmsResponse>);
}
}

View File

@@ -1,51 +1,38 @@
using AutoMapper;
using DigitalData.Core.Application;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Infrastructure.Contracts;
using EnvelopeGenerator.Application.DTOs.Receiver;
using DigitalData.Core.DTO;
using DigitalData.Core.Abstractions;
using Microsoft.Extensions.Logging;
using EnvelopeGenerator.Application.Contracts.Services;
namespace EnvelopeGenerator.Application.Services;
public class ReceiverService : CRUDService<IReceiverRepository, ReceiverCreateDto, ReceiverReadDto, ReceiverUpdateDto, Receiver, int>, IReceiverService
namespace EnvelopeGenerator.Application.Services
{
public ReceiverService(IReceiverRepository repository, IMapper mapper)
: base(repository, mapper)
public class ReceiverService : CRUDService<IReceiverRepository, ReceiverCreateDto, ReceiverReadDto, ReceiverUpdateDto, Receiver, int>, IReceiverService
{
}
public async Task<DataResult<ReceiverReadDto>> ReadByAsync(string? emailAddress = null, string? signature = null)
{
var rcv = await _repository.ReadByAsync(emailAddress: emailAddress, signature: signature);
if (rcv is null)
return Result.Fail<ReceiverReadDto>();
return Result.Success(_mapper.Map<ReceiverReadDto>(rcv));
}
public async Task<Result> DeleteByAsync(string? emailAddress = null, string? signature = null)
{
var rcv = await _repository.ReadByAsync(emailAddress: emailAddress, signature: signature);
if (rcv is null)
return Result.Fail();
return await _repository.DeleteAsync(rcv) ? Result.Success() : Result.Fail();
}
public virtual async Task<Result> UpdateAsync<TUpdateDto>(TUpdateDto updateDto) where TUpdateDto : IUnique<int>
{
var val = await _repository.ReadByIdAsync(updateDto.Id);
if (val == null)
public ReceiverService(IReceiverRepository repository, IMapper mapper)
: base(repository, mapper)
{
return Result.Fail().Notice(LogLevel.Warning, Flag.NotFound, $"{updateDto.Id} is not found in update process of {GetType()} entity.");
}
var entity = _mapper.Map(updateDto, val);
return (await _repository.UpdateAsync(entity)) ? Result.Success() : Result.Fail();
public async Task<DataResult<ReceiverReadDto>> ReadByAsync(string? emailAddress = null, string? signature = null)
{
var rcv = await _repository.ReadByAsync(emailAddress: emailAddress, signature: signature);
if (rcv is null)
return Result.Fail<ReceiverReadDto>();
return Result.Success(_mapper.Map<ReceiverReadDto>(rcv));
}
public async Task<Result> DeleteByAsync(string? emailAddress = null, string? signature = null)
{
var rcv = await _repository.ReadByAsync(emailAddress: emailAddress, signature: signature);
if (rcv is null)
return Result.Fail();
return await _repository.DeleteAsync(rcv) ? Result.Success() : Result.Fail();
}
}
}

View File

@@ -1,16 +1,17 @@
using AutoMapper;
using DigitalData.Core.Application;
using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Contracts.Repositories;
using EnvelopeGenerator.Infrastructure.Contracts;
namespace EnvelopeGenerator.Application.Services;
public class UserReceiverService : BasicCRUDService<IUserReceiverRepository, UserReceiverDto, UserReceiver, int>, IUserReceiverService
namespace EnvelopeGenerator.Application.Services
{
public UserReceiverService(IUserReceiverRepository repository, IMapper mapper)
: base(repository, mapper)
public class UserReceiverService : BasicCRUDService<IUserReceiverRepository, UserReceiverDto, UserReceiver, int>, IUserReceiverService
{
public UserReceiverService(IUserReceiverRepository repository, IMapper mapper)
: base(repository, mapper)
{
}
}
}

View File

@@ -77,9 +77,8 @@
End Enum
Public Enum CertificationType
AdvancedElectronicSignature = 1
'ElectronicSignature = 1
'QualifiedSignature = 2
ElectronicSignature = 1
QualifiedSignature = 2
End Enum
Public Enum FinalEmailType
@@ -100,7 +99,6 @@
DocumentCompleted
DocumentAccessCodeReceived
DocumentShared
TotpSecret
End Enum
Public Enum EncodeType
@@ -110,13 +108,7 @@
DocumentForwarded
DocumentShared
End Enum
#End Region
#Region "Role"
Public NotInheritable Class ReceiverRole
Public Const PreAuth As String = "PreAuth"
Public Const FullyAuth As String = "FullyAuth"
End Class
#End Region
#Region "Constants"

View File

@@ -3,9 +3,13 @@
Public Property DocumentPathOrigin As String = ""
Public Property DocumentPath As String = ""
Public Property ExportPath As String = ""
Public Property DocumentPath_DMZ As String = ""
Public Property ExportPath_DMZ As String = ""
Public Property DOCUMENT_PATH_MOVE_AFTSEND As String = ""
Public Property FINISHED_PATH_EX_DMZ As String = ""
Public Property EML_PATH_EX_DMZ As String = ""
Public Property SendingProfile As Integer = 0
Public Property SignatureHost As String = ""
Public Property Default_TFA_Enabled As Boolean = False
Public Property Default_TFA_WithPhone As Boolean = False
Public Property NetUse_necessary As Boolean = False
Public Property NetUse_Finish As Boolean = False
End Class

View File

@@ -8,8 +8,8 @@
Public Property Uuid As String = Guid.NewGuid.ToString()
Public Property UseAccessCode As Boolean = False
Public Property Language As String = "de-DE"
Public Property CertificationType As Constants.CertificationType = Constants.CertificationType.AdvancedElectronicSignature
Public Property TFA_Enabled As Boolean = False
Public Property CertificationType As Constants.CertificationType = Constants.CertificationType.ElectronicSignature
Public Property SendReminderEmails As Boolean = False
Public Property FirstReminderDays As Integer = 0
Public Property ReminderIntervalDays As Integer = 0

View File

@@ -75,7 +75,6 @@ Public Class EnvelopeReceiver
Public Property Sequence As Integer = 0
Public Property PrivateMessage As String = ""
Public Property AccessCode As String = ""
Public Property PhoneNumber As String = ""
Public Function GetSignature() As String
Return StringEx.GetChecksum(Email.ToUpper)

View File

@@ -6,8 +6,7 @@
Public Property ContractType As Integer ' Unbenutzt
Public Property Language As String
Public Property CertificationType As Constants.CertificationType = Constants.CertificationType.AdvancedElectronicSignature
Public Property TFA_Enabled As Boolean = False
Public Property CertificationType As Constants.CertificationType = Constants.CertificationType.ElectronicSignature
Public Property SendReminderEmails As Boolean = False
Public Property FirstReminderDays As Integer = 0
Public Property ReminderIntervalDays As Integer = 0

View File

@@ -77,8 +77,8 @@
<Reference Include="DigitalData.Modules.Logging">
<HintPath>..\..\2_DLL Projekte\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
</Reference>
<Reference Include="GdPicture.NET.14, Version=14.2.90.0, Culture=neutral, PublicKeyToken=f52a2e60ad468dbb, processorArchitecture=MSIL">
<HintPath>..\packages\GdPicture.14.2.90\lib\net462\GdPicture.NET.14.dll</HintPath>
<Reference Include="GdPicture.NET.14, Version=14.2.89.0, Culture=neutral, PublicKeyToken=f52a2e60ad468dbb, processorArchitecture=MSIL">
<HintPath>..\packages\GdPicture.14.2.89\lib\net462\GdPicture.NET.14.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
@@ -260,13 +260,11 @@
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Model.en.Designer.vb</LastGenOutput>
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Strings\Model.resx">
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Model.Designer.vb</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
@@ -291,11 +289,11 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<Import Project="..\packages\GdPicture.runtimes.windows.14.2.90\build\net462\GdPicture.runtimes.windows.targets" Condition="Exists('..\packages\GdPicture.runtimes.windows.14.2.90\build\net462\GdPicture.runtimes.windows.targets')" />
<Import Project="..\packages\GdPicture.runtimes.windows.14.2.89\build\net462\GdPicture.runtimes.windows.targets" Condition="Exists('..\packages\GdPicture.runtimes.windows.14.2.89\build\net462\GdPicture.runtimes.windows.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\GdPicture.runtimes.windows.14.2.90\build\net462\GdPicture.runtimes.windows.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\GdPicture.runtimes.windows.14.2.90\build\net462\GdPicture.runtimes.windows.targets'))" />
<Error Condition="!Exists('..\packages\GdPicture.runtimes.windows.14.2.89\build\net462\GdPicture.runtimes.windows.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\GdPicture.runtimes.windows.14.2.89\build\net462\GdPicture.runtimes.windows.targets'))" />
</Target>
</Project>

View File

@@ -82,14 +82,49 @@ Namespace Jobs
Logger.Debug("Loading ReportCreator..")
ReportCreator = New ReportCreator(LogConfig, oState)
Logger.Debug("My.Settings.RuninDMZ: [{0}]", My.Settings.RuninDMZ.ToString)
Logger.Debug("My.Settings.NetUse_Usr: [{0}]", My.Settings.NetUse_Usr)
Config.DocumentPath = Config.DocumentPath
If My.Settings.RuninDMZ = True Then
If Config.DocumentPath_DMZ <> String.Empty Then
Logger.Debug("RuninDMZ - Using DocumentPath_DMZ: [{0}] - Overwrite Document-Path", Config.DocumentPath_DMZ)
Config.DocumentPath = Config.DocumentPath_DMZ
Config.NetUse_necessary = True
Else
Config.DocumentPath = Config.DocumentPath
End If
Else
If Config.DOCUMENT_PATH_MOVE_AFTSEND <> String.Empty Then
Logger.Debug("Using DMZRemotePath: [{0}] - Overwrite Document-Path ...", Config.DOCUMENT_PATH_MOVE_AFTSEND)
Config.DocumentPath = Config.DOCUMENT_PATH_MOVE_AFTSEND
Config.NetUse_Finish = True
Else
Config.DocumentPath = Config.DocumentPath
End If
End If
Logger.Debug("DocumentPath: [{0}]", Config.DocumentPath)
If My.Settings.RuninDMZ = True Then
If Config.FINISHED_PATH_EX_DMZ <> String.Empty Then
Logger.Debug("RuninDMZ - FINISHED_PATH_EX_DMZ configured: [{0}]", Config.FINISHED_PATH_EX_DMZ)
Config.NetUse_Finish = True
End If
If Config.ExportPath_DMZ <> String.Empty Then
Logger.Debug("RuninDMZ - Using ExportPath_DMZ: [{0}] - Overwrite ExportPath", Config.ExportPath_DMZ)
Config.ExportPath = Config.ExportPath_DMZ
End If
End If
Logger.Debug("ExportPath: [{0}]", Config.ExportPath)
If Config.NetUse_Finish = True Then
If NetUse_Command(Config.DocumentPath, My.Settings.NetUse_Usr, My.Settings.NetUse_PW) = True Then
Logger.Debug("NetUse_Finish = successful!")
End If
End If
Dim oCompleteStatus As Integer = Constants.EnvelopeStatus.EnvelopeCompletelySigned
Dim oSql = $"SELECT * FROM TBSIG_ENVELOPE WHERE STATUS = {oCompleteStatus} AND DATEDIFF(minute, CHANGED_WHEN, GETDATE()) >= {CompleteWaitTime} ORDER BY GUID"
Dim oTable = Database.GetDatatable(oSql)
@@ -122,6 +157,10 @@ Namespace Jobs
Logger.Warn("EnvelopeData could not be loaded for Id [{0}]!", oId)
Throw New ArgumentNullException("EnvelopeData")
End If
If Config.DOCUMENT_PATH_MOVE_AFTSEND <> String.Empty Then
oEnvelopeData.DocumentPath.Replace(Config.DocumentPathOrigin, Config.DOCUMENT_PATH_MOVE_AFTSEND)
Logger.Debug("Replaced Path in oEnvelopeData.DocumentPath!")
End If
Logger.Debug("Burning Annotations to pdf ...")
Dim oBurnedDocument As Byte() = BurnAnnotationsToPdf(oEnvelopeData)
If oBurnedDocument Is Nothing Then
@@ -157,6 +196,13 @@ Namespace Jobs
Throw New ExportDocumentException("Could not export final document to disk!", ex)
End Try
If Config.NetUse_Finish = True Then
If Config.FINISHED_PATH_EX_DMZ <> String.Empty Then
If My.Settings.NetUse_PW <> String.Empty And My.Settings.NetUse_Usr <> String.Empty Then
Clean_DNZ_PAth(Config.FINISHED_PATH_EX_DMZ)
End If
End If
End If
Logger.Info("Writing EB-bytes to database...")
Update_File_DB(oOutputFilePath, oEnvelope.Id)
@@ -241,48 +287,48 @@ Namespace Jobs
data = br.ReadBytes(CInt(numBytes))
Return data
End Function
'Private Function NetUse_Command(pDestinationPath As String, pUsername As String, pPassword As String)
' Dim oDectryptedPW = Helpers.Decrypt(My.Settings.NetUse_PW)
' Dim netUseCommand As String = $"net use {pDestinationPath} /user:{pUsername} {oDectryptedPW}"
' Logger.Debug("EXECUTING NetUse_Command for " & pDestinationPath)
' Dim processInfo As New ProcessStartInfo("cmd.exe", $"/C {netUseCommand}")
' processInfo.RedirectStandardOutput = True
' processInfo.UseShellExecute = False
' processInfo.CreateNoWindow = True
Private Function NetUse_Command(pDestinationPath As String, pUsername As String, pPassword As String)
Dim oDectryptedPW = Helpers.Decrypt(My.Settings.NetUse_PW)
Dim netUseCommand As String = $"net use {pDestinationPath} /user:{pUsername} {oDectryptedPW}"
Logger.Debug("EXECUTING NetUse_Command for " & pDestinationPath)
Dim processInfo As New ProcessStartInfo("cmd.exe", $"/C {netUseCommand}")
processInfo.RedirectStandardOutput = True
processInfo.UseShellExecute = False
processInfo.CreateNoWindow = True
' Using process As Process = Process.Start(processInfo)
' process.WaitForExit()
Using process As Process = Process.Start(processInfo)
process.WaitForExit()
' ' Prüfe den Rückgabewert des net use Befehls
' If process.ExitCode = 0 Then
' Return True
' Else
' Return False
' End If
' End Using
'End Function
' Prüfe den Rückgabewert des net use Befehls
If process.ExitCode = 0 Then
Return True
Else
Return False
End If
End Using
End Function
'Private Function Clean_DNZ_PAth(pSourcePath As String) As Boolean
' Dim oFilename = System.IO.Path.GetFileName(pSourcePath)
Private Function Clean_DNZ_PAth(pSourcePath As String) As Boolean
Dim oFilename = System.IO.Path.GetFileName(pSourcePath)
' Logger.Debug("## Starting Clean_DNZ_PAth ...")
' Logger.Debug("## pSourcePath {0}", pSourcePath)
Logger.Debug("## Starting Clean_DNZ_PAth ...")
Logger.Debug("## pSourcePath {0}", pSourcePath)
' Dim oDirectorySource = Path.Combine(pSourcePath, ParentFolderUID)
Dim oDirectorySource = Path.Combine(pSourcePath, ParentFolderUID)
' Try
' Logger.Debug($"Deleting oDirectorySource {oDirectorySource} ...")
' Directory.Delete(oDirectorySource, True)
' Console.WriteLine($"Folder successfully deleted!")
' Logger.Debug($"...Deleted!")
' Return True
' Catch ex As Exception
' Logger.Error(ex)
' Return False
' End Try
Try
Logger.Debug($"Deleting oDirectorySource {oDirectorySource} ...")
Directory.Delete(oDirectorySource, True)
Console.WriteLine($"Folder successfully deleted!")
Logger.Debug($"...Deleted!")
Return True
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
'End Function
End Function
Private Function SendFinalEmails(pEnvelope As Envelope) As Boolean ', pAttachment As String
Dim oMailToCreator = pEnvelope.FinalEmailToCreator
Dim oMailToReceivers = pEnvelope.FinalEmailToReceivers
@@ -352,7 +398,15 @@ Namespace Jobs
Dim oAnnotations = pEnvelopeData.AnnotationData
Dim oInputPath = ""
If IsNothing(pEnvelopeData.DocAsByte) Then
oInputPath = pEnvelopeData.DocumentPath
If My.Settings.RuninDMZ Then
Logger.Debug("Replacing Path in pData.DocumentPath ...")
oInputPath = pEnvelopeData.DocumentPath.Replace(Config.DocumentPathOrigin, Config.DocumentPath)
ElseIf Config.DOCUMENT_PATH_MOVE_AFTSEND <> String.Empty Then
Logger.Debug("Replacing Path in pData.DocumentPath ...")
oInputPath = pEnvelopeData.DocumentPath.Replace(Config.DocumentPathOrigin, Config.DOCUMENT_PATH_MOVE_AFTSEND)
Else
oInputPath = pEnvelopeData.DocumentPath
End If
Logger.Info($"Input path: [{oInputPath}]")
Else
Logger.Info($"we got bytes..")

View File

@@ -16,14 +16,17 @@ Public Class ConfigModel
Dim oRow As DataRow = oTable.Rows.Item(0)
Return New DbConfig() With {
.DocumentPath = oRow.ItemEx("DOCUMENT_PATH", ""),
.DocumentPathOrigin = oRow.ItemEx("DOCUMENT_PATH", ""),
.ExportPath = oRow.ItemEx("EXPORT_PATH", ""),
.SendingProfile = oRow.ItemEx("SENDING_PROFILE", 0),
.SignatureHost = oRow.ItemEx("SIGNATURE_HOST", ""),
.ExternalProgramName = oRow.ItemEx("EXTERNAL_PROGRAM_NAME", ""),
.Default_TFA_Enabled = oRow.ItemEx("DEF_TFA_ENABLED", False),
.Default_TFA_WithPhone = oRow.ItemEx("DEF_TFA_WITH_PHONE", False)
.DocumentPath = oRow.ItemEx("DOCUMENT_PATH", ""),
.DocumentPathOrigin = oRow.ItemEx("DOCUMENT_PATH", ""),
.DocumentPath_DMZ = oRow.ItemEx("DOCUMENT_PATH_DMZ", ""),
.ExportPath = oRow.ItemEx("EXPORT_PATH", ""),
.ExportPath_DMZ = oRow.ItemEx("EXPORT_PATH_DMZ", ""),
.SendingProfile = oRow.ItemEx("SENDING_PROFILE", 0),
.SignatureHost = oRow.ItemEx("SIGNATURE_HOST", ""),
.ExternalProgramName = oRow.ItemEx("EXTERNAL_PROGRAM_NAME", ""),
.DOCUMENT_PATH_MOVE_AFTSEND = oRow.ItemEx("DOCUMENT_PATH_MOVE_AFTSEND", ""),
.FINISHED_PATH_EX_DMZ = oRow.ItemEx("FINISHED_PATH_EX_DMZ", ""),
.EML_PATH_EX_DMZ = oRow.ItemEx("EML_PATH_EX_DMZ", "")
}
Catch ex As Exception
Logger.Error(ex)

View File

@@ -2,7 +2,6 @@
Imports System.Web.UI.WebControls
Imports DigitalData.Modules.Base
Imports DigitalData.Modules.Logging
Imports EnvelopeGenerator.Common.Constants
Public Class EnvelopeModel
Inherits BaseModel
@@ -35,7 +34,7 @@ Public Class EnvelopeModel
.Language = pRow.ItemEx("LANGUAGE", "de-DE"),
.Status = ObjectEx.ToEnum(Of Constants.EnvelopeStatus)(pRow.ItemEx("STATUS", Constants.EnvelopeStatus.EnvelopeCreated.ToString())),
.AddedWhen = pRow.Item("ADDED_WHEN"),
.CertificationType = ObjectEx.ToEnum(Of Constants.CertificationType)(pRow.ItemEx("CERTIFICATION_TYPE", Constants.CertificationType.AdvancedElectronicSignature.ToString())),
.CertificationType = ObjectEx.ToEnum(Of Constants.CertificationType)(pRow.ItemEx("CERTIFICATION_TYPE", Constants.CertificationType.ElectronicSignature.ToString())),
.User = New User(),
.ExpiresWhen = pRow.ItemEx(Of Date)("EXPIRES_WHEN", Nothing),
.ExpiresWarningWhen = pRow.ItemEx(Of Date)("EXPIRES_WARNING_WHEN", Nothing),
@@ -46,8 +45,7 @@ Public Class EnvelopeModel
.ReminderIntervalDays = pRow.ItemEx("REMINDER_INTERVAL_DAYS", 0),
.UseAccessCode = pRow.ItemEx("USE_ACCESS_CODE", False),
.FinalEmailToCreator = ObjectEx.ToEnum(Of Constants.FinalEmailType)(pRow.ItemEx("FINAL_EMAIL_TO_CREATOR", Constants.FinalEmailType.No.ToString())),
.FinalEmailToReceivers = ObjectEx.ToEnum(Of Constants.FinalEmailType)(pRow.ItemEx("FINAL_EMAIL_TO_RECEIVERS", Constants.FinalEmailType.No.ToString())),
.TFA_Enabled = pRow.ItemEx("TFA_Enabled", False)
.FinalEmailToReceivers = ObjectEx.ToEnum(Of Constants.FinalEmailType)(pRow.ItemEx("FINAL_EMAIL_TO_RECEIVERS", Constants.FinalEmailType.No.ToString()))
}
Dim oDOC_RESULT = pRow.Item("DOC_RESULT")
If Not IsDBNull(oDOC_RESULT) Then
@@ -144,17 +142,13 @@ Public Class EnvelopeModel
Public Function Insert(pEnvelope As Envelope) As Boolean
Try
Dim oSql = $"INSERT INTO [dbo].[TBSIG_ENVELOPE] (MESSAGE, ENVELOPE_UUID, STATUS, USER_ID)
VALUES('',
'{pEnvelope.Uuid}',
'{CInt([Enum].Parse(GetType(EnvelopeStatus), Constants.EnvelopeStatus.EnvelopeCreated))}',
'{pEnvelope.UserId}')"
Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE] (MESSAGE, ENVELOPE_UUID, STATUS, USER_ID) "
oSql += " VALUES (@MESSAGE, @UUID, @STATUS, @USER_ID)"
Dim oCommand As New SqlCommand(oSql)
'oCommand.Parameters.Add("MESSAGE", SqlDbType.NVarChar).Value = String.Empty
'oCommand.Parameters.Add("UUID", SqlDbType.NVarChar).Value = pEnvelope.Uuid
'oCommand.Parameters.Add("STATUS", SqlDbType.Int).Value = Constants.EnvelopeStatus.EnvelopeCreated
'oCommand.Parameters.Add("USER_ID", SqlDbType.Int).Value = pEnvelope.UserId
oCommand.Parameters.Add("MESSAGE", SqlDbType.NVarChar).Value = String.Empty
oCommand.Parameters.Add("UUID", SqlDbType.NVarChar).Value = pEnvelope.Uuid
oCommand.Parameters.Add("STATUS", SqlDbType.Int).Value = Constants.EnvelopeStatus.EnvelopeCreated
oCommand.Parameters.Add("USER_ID", SqlDbType.Int).Value = pEnvelope.UserId
If Database.ExecuteNonQuery(oCommand) Then
pEnvelope.Id = GetEnvelopeId(pEnvelope)
@@ -188,11 +182,9 @@ Public Class EnvelopeModel
oSql += " [REMINDER_INTERVAL_DAYS] = @REMINDER_INTERVAL_DAYS, "
oSql += " [SEND_REMINDER_EMAILS] = @SEND_REMINDER_EMAILS, "
oSql += " [USE_ACCESS_CODE] = @USE_ACCESS_CODE, "
oSql += " [CHANGED_WHEN] = GETDATE(), "
oSql += " [TFA_Enabled] = @TFA_Enabled"
oSql += " [CHANGED_WHEN] = GETDATE() "
oSql += " WHERE GUID = @ID AND USER_ID = @USER_ID"
Dim oCommand As New SqlCommand(oSql)
oCommand.Parameters.Add("ID", SqlDbType.Int).Value = pEnvelope.Id
oCommand.Parameters.Add("USER_ID", SqlDbType.Int).Value = pEnvelope.UserId
@@ -214,7 +206,7 @@ Public Class EnvelopeModel
oCommand.Parameters.Add("REMINDER_INTERVAL_DAYS", SqlDbType.Int).Value = pEnvelope.ReminderIntervalDays
oCommand.Parameters.Add("SEND_REMINDER_EMAILS", SqlDbType.Bit).Value = pEnvelope.SendReminderEmails
oCommand.Parameters.Add("USE_ACCESS_CODE", SqlDbType.Bit).Value = pEnvelope.UseAccessCode
oCommand.Parameters.Add("TFA_ENABLED", SqlDbType.Bit).Value = pEnvelope.TFA_Enabled
Return Database.ExecuteNonQuery(oCommand, pTransaction)
Catch ex As Exception

View File

@@ -1,5 +1,4 @@
Imports DigitalData.Modules.Base
Imports EnvelopeGenerator.Common.Constants
Public Class EnvelopeTypeModel
Inherits BaseModel
@@ -22,8 +21,7 @@ Public Class EnvelopeTypeModel
.FinalEmailToCreator = pRow.ItemEx("FINAL_EMAIL_TO_CREATOR", 0),
.FinalEmailToReceivers = pRow.ItemEx("FINAL_EMAIL_TO_RECEIVERS", 0),
.ContractType = pRow.ItemEx("CONTRACT_TYPE", 0),
.CertificationType = pRow.ItemEx("CERTIFICATION_TYPE", 0),
.TFA_Enabled = pRow.ItemEx("TFA_Enabled", 0)
.CertificationType = pRow.ItemEx("CERTIFICATION_TYPE", 0)
}
End Function

View File

@@ -33,8 +33,7 @@ Public Class ReceiverModel
.Status = ReceiverSignedStatus,
.ColorType = DirectCast(pColorIndex + 1, ColorType),
.AccessCode = pRow.ItemEx("ACCESS_CODE", ""),
.SignedDate = SignedDate,
.PhoneNumber = pRow.ItemEx("PHONE_NUMBER", "")
.SignedDate = SignedDate
}
End Function
@@ -57,29 +56,25 @@ Public Class ReceiverModel
Public Function Insert(pReceiver As EnvelopeReceiver, pTransaction As SqlTransaction) As Boolean
Try
Dim oCheck = $"SELECT COUNT(GUID) FROM [dbo].[TBSIG_RECEIVER] WHERE SIGNATURE = '{pReceiver.GetSignature()}'"
Dim oExists = Database.GetScalarValue(oCheck)
If oExists = 0 Then
Dim oSql As String = $"INSERT INTO [dbo].[TBSIG_RECEIVER]
Dim oSql As String = "INSERT INTO [dbo].[TBSIG_RECEIVER]
([EMAIL_ADDRESS]
,[SIGNATURE])
VALUES
('{pReceiver.Email}'
,'{pReceiver.GetSignature()}')"
(@EMAIL
,@SIGNATURE)"
Dim oCommand = New SqlCommand(oSql)
Dim oResult = Database.ExecuteNonQuery(oCommand)
If oResult = True Then
pReceiver.Id = GetReceiverIdByEmail(pReceiver.Email, pTransaction)
Return True
Else
Return False
End If
Dim oCommand = New SqlCommand(oSql)
oCommand.Parameters.Add("EMAIL", SqlDbType.NVarChar).Value = pReceiver.Email
oCommand.Parameters.Add("SIGNATURE", SqlDbType.NVarChar).Value = pReceiver.GetSignature()
Dim oResult = Database.ExecuteNonQuery(oCommand)
If oResult = True Then
pReceiver.Id = GetReceiverIdByEmail(pReceiver.Email, pTransaction)
Else
Logger.Warn($"Receiver [{pReceiver.Email}] already existing! Check collecting not existing Receivers!")
Return True
Return False
End If
Return True
Catch ex As Exception
Logger.Error(ex)
Return False
@@ -88,18 +83,18 @@ Public Class ReceiverModel
Public Function Update(pReceiver As EnvelopeReceiver, pTransaction As SqlTransaction) As Boolean
Try
Dim oSql As String = $"UPDATE [dbo].[TBSIG_USER_RECEIVER]
SET [NAME] = '{pReceiver.Name}'
,[COMPANY_NAME] = '{pReceiver.Company}'
,[JOB_TITLE] = '{pReceiver.JobTitle}'
WHERE RECEIVER_ID = {pReceiver.Id}"
Dim oSql As String = "UPDATE [dbo].[TBSIG_USER_RECEIVER]
SET [NAME] = @NAME
,[COMPANY_NAME] = @COMPANY
,[JOB_TITLE] = @JOB
WHERE RECEIVER_ID = @RECEIVER_ID"
Dim oCommand = New SqlCommand(oSql)
'oCommand.Parameters.Add("NAME", SqlDbType.NVarChar).Value = pReceiver.Name
'oCommand.Parameters.Add("COMPANY", SqlDbType.NVarChar).Value = pReceiver.Company
'oCommand.Parameters.Add("JOB", SqlDbType.NVarChar).Value = pReceiver.JobTitle
'oCommand.Parameters.Add("RECEIVER_ID", SqlDbType.Int).Value = pReceiver.Id
'oCommand.Parameters.Add("USER_ID", SqlDbType.Int).Value = pReceiver.Id
oCommand.Parameters.Add("NAME", SqlDbType.NVarChar).Value = pReceiver.Name
oCommand.Parameters.Add("COMPANY", SqlDbType.NVarChar).Value = pReceiver.Company
oCommand.Parameters.Add("JOB", SqlDbType.NVarChar).Value = pReceiver.JobTitle
oCommand.Parameters.Add("RECEIVER_ID", SqlDbType.Int).Value = pReceiver.Id
oCommand.Parameters.Add("USER_ID", SqlDbType.Int).Value = pReceiver.Id
Return Database.ExecuteNonQuery(oCommand, pTransaction)
Catch ex As Exception
@@ -118,7 +113,7 @@ Public Class ReceiverModel
End Function
Public Function Assign(pEnvelope As Envelope, pReceiver As EnvelopeReceiver, pTransaction As SqlTransaction) As Boolean
Dim oSql = $"INSERT INTO [dbo].[TBSIG_ENVELOPE_RECEIVER]
Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE_RECEIVER]
([ENVELOPE_ID]
,[RECEIVER_ID]
,[PRIVATE_MESSAGE]
@@ -126,28 +121,26 @@ Public Class ReceiverModel
,[NAME]
,[JOB_TITLE]
,[COMPANY_NAME]
,[SEQUENCE]
,[PHONE_NUMBER])
,[SEQUENCE])
VALUES
('{pEnvelope.Id}'
,'{pReceiver.Id}'
,'{pReceiver.PrivateMessage}'
,'{pReceiver.AccessCode}'
,'{pReceiver.Name}'
,'{pReceiver.JobTitle}'
,'{pReceiver.Company}'
,'{pReceiver.Sequence}'
,'{pReceiver.PhoneNumber}')"
(@ENVELOPE_ID
,@RECEIVER_ID
,@MESSAGE
,@ACCESS_CODE
,@NAME
,@JOB
,@COMPANY
,@SEQUENCE)"
Dim oCommand As New SqlCommand(oSql)
'oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.NVarChar).Value = pEnvelope.Id
'oCommand.Parameters.Add("RECEIVER_ID", SqlDbType.NVarChar).Value = pReceiver.Id
'oCommand.Parameters.Add("MESSAGE", SqlDbType.NVarChar).Value = pReceiver.PrivateMessage
'oCommand.Parameters.Add("ACCESS_CODE", SqlDbType.NVarChar).Value = pReceiver.AccessCode
'oCommand.Parameters.Add("NAME", SqlDbType.NVarChar).Value = pReceiver.Name
'oCommand.Parameters.Add("JOB", SqlDbType.NVarChar).Value = pReceiver.JobTitle
'oCommand.Parameters.Add("COMPANY", SqlDbType.NVarChar).Value = pReceiver.Company
'oCommand.Parameters.Add("SEQUENCE", SqlDbType.NVarChar).Value = pReceiver.Sequence
oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.NVarChar).Value = pEnvelope.Id
oCommand.Parameters.Add("RECEIVER_ID", SqlDbType.NVarChar).Value = pReceiver.Id
oCommand.Parameters.Add("MESSAGE", SqlDbType.NVarChar).Value = pReceiver.PrivateMessage
oCommand.Parameters.Add("ACCESS_CODE", SqlDbType.NVarChar).Value = pReceiver.AccessCode
oCommand.Parameters.Add("NAME", SqlDbType.NVarChar).Value = pReceiver.Name
oCommand.Parameters.Add("JOB", SqlDbType.NVarChar).Value = pReceiver.JobTitle
oCommand.Parameters.Add("COMPANY", SqlDbType.NVarChar).Value = pReceiver.Company
oCommand.Parameters.Add("SEQUENCE", SqlDbType.NVarChar).Value = pReceiver.Sequence
Return Database.ExecuteNonQuery(oCommand, pTransaction)
End Function
@@ -273,22 +266,6 @@ Public Class ReceiverModel
Return String.Empty
End Try
End Function
Public Function GetLastUsedReceiverPhone(pEmailAddress As String, pUserId As Integer) As String
Try
Dim oSql As String
oSql = "SELECT TOP 1 [PHONE_NUMBER] FROM dbo.VWSIG_ENVELOPE_RECEIVERS "
oSql += $" WHERE ENV_USERID_CREATED = {pUserId} "
oSql += $" AND EMAIL_ADDRESS = '{pEmailAddress}' "
oSql += " AND Len([PHONE_NUMBER]) > 0 "
oSql += " ORDER BY [ADDED_WHEN] DESC"
Return Database.GetScalarValue(oSql)
Catch ex As Exception
Logger.Error(ex)
Return String.Empty
End Try
End Function
Private Function GetReceiverIdByEmail(pEmailAddress As String, pTransaction As SqlTransaction) As Integer
Try

View File

@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' indem Sie "*" wie unten gezeigt eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("2.3.0.0")>
<Assembly: AssemblyFileVersion("2.3.0.0")>
<Assembly: AssemblyVersion("1.9.3.0")>
<Assembly: AssemblyFileVersion("1.9.3.0")>

Some files were not shown because too many files have changed in this diff Show More