Files
EnvelopeGenerator/EnvelopeGenerator.Domain/Entities/Envelope.cs
TekH e2afbc5a62 Add audit interfaces and fields to domain entities
Introduced interfaces for audit fields (AddedWhen, ChangedWhen, ChangedWho, AddedWho) and updated domain entities to implement them. Adjusted properties for consistency and nullability. Updated MappingProfile to map audit fields between DTOs and entities. Improves auditability and standardization across the domain model.
2026-02-09 15:11:42 +01:00

208 lines
5.2 KiB
C#

using System;
using EnvelopeGenerator.Domain.Interfaces;
using DigitalData.UserManager.Domain.Entities;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using EnvelopeGenerator.Domain.Constants;
using Newtonsoft.Json;
#if NETFRAMEWORK
using System.Collections.Generic;
using System.Linq;
#endif
namespace EnvelopeGenerator.Domain.Entities
#if NET
;
#elif NETFRAMEWORK
{
#endif
[Table("TBSIG_ENVELOPE", Schema = "dbo")]
public class Envelope : IHasAddedWhen, IHasChangedWhen
{
public Envelope()
{
// TODO: * Check the Form App and remove the default value
#if NETFRAMEWORK
Id = 0;
Status = EnvelopeStatus.EnvelopeCreated;
Uuid = Guid.NewGuid().ToString();
Message = My.Resources.Envelope.Please_read_and_sign_this_document;
Title= string.Empty;
Comment = string.Empty;
Language = "de-DE";
SendReminderEmails = false;
FirstReminderDays = 0;
ReminderIntervalDays = 0;
CertificationType = (int)Constants.CertificationType.AdvancedElectronicSignature;
UseAccessCode = false;
Documents = Enumerable.Empty<Document>().ToList();
Histories = Enumerable.Empty<History>().ToList();
EnvelopeReceivers = Enumerable.Empty<EnvelopeReceiver>().ToList();
#endif
}
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column("GUID")]
public int Id { get; set; }
[Required]
[Column("USER_ID")]
public int UserId { get; set; }
[Required]
[Column("STATUS")]
public EnvelopeStatus Status { get; set; }
[Required]
[Column("ENVELOPE_UUID", TypeName = "nvarchar(36)")]
public string Uuid { get; set; }
[Column("MESSAGE", TypeName = "nvarchar(max)")]
public string Message { get; set; }
[Column("EXPIRES_WHEN", TypeName = "datetime")]
public DateTime? ExpiresWhen { get; set; }
[Column("EXPIRES_WARNING_WHEN", TypeName = "datetime")]
public DateTime? ExpiresWarningWhen { get; set; }
[Required]
[Column("ADDED_WHEN", TypeName = "datetime")]
public DateTime AddedWhen { get; set; }
[Column("CHANGED_WHEN", TypeName = "datetime")]
public DateTime? ChangedWhen { get; set; }
[Column("TITLE", TypeName = "nvarchar(128)")]
public string
#if nullable
?
#endif
Title { get; set; }
[Column("COMMENT", TypeName = "nvarchar(128)")]
public string Comment { get; set; }
[Column("CONTRACT_TYPE")]
public int? ContractType { get; set; }
#if NETFRAMEWORK
[NotMapped]
public string ContractTypeTranslated => My.Resources.Model.ResourceManager.GetString(ContractType.ToString());
#endif
[Column("LANGUAGE", TypeName = "nvarchar(5)")]
public string Language { get; set; }
[Column("SEND_REMINDER_EMAILS")]
public bool SendReminderEmails { get; set; }
[Column("FIRST_REMINDER_DAYS")]
public int? FirstReminderDays { get; set; }
[Column("REMINDER_INTERVAL_DAYS")]
public int? ReminderIntervalDays { get; set; }
[Column("ENVELOPE_TYPE")]
public int? EnvelopeTypeId { get; set; }
[JsonIgnore]
[NotMapped]
public bool ReadOnly => EnvelopeTypeId == 2;
[Column("CERTIFICATION_TYPE")]
public int? CertificationType { get; set; }
[Column("USE_ACCESS_CODE")]
public bool UseAccessCode { get; set; }
[Column("FINAL_EMAIL_TO_CREATOR")]
public int? FinalEmailToCreator { get; set; }
[Column("FINAL_EMAIL_TO_RECEIVERS")]
public int? FinalEmailToReceivers { get; set; }
[Column("EXPIRES_WHEN_DAYS")]
public int? ExpiresWhenDays { get; set; }
[Column("EXPIRES_WARNING_WHEN_DAYS")]
public int? ExpiresWarningWhenDays { get; set; }
[ForeignKey("UserId")]
public User User { get; set; }
[Column("TFA_ENABLED")]
public bool TfaEnabled { get; set; }
#if NETFRAMEWORK
= false;
#endif
[NotMapped]
[Column("DOC_RESULT")]
public byte[]
#if nullable
?
#endif
DocResult { get; set; }
[ForeignKey("EnvelopeTypeId")]
public virtual EnvelopeType
#if nullable
?
#endif
Type { get; set; }
#if NETFRAMEWORK
[NotMapped]
public string CURRENT_WORK_APP { get; set; } = "signFLOW GUI";
[NotMapped]
public bool IsAlreadySent => Status > EnvelopeStatus.EnvelopeSaved;
#endif
public List<Document>
#if nullable
?
#endif
Documents { get; set; }
public List<History>
#if nullable
?
#endif
Histories { get; set; }
public List<EnvelopeReceiver>
#if nullable
?
#endif
EnvelopeReceivers { get; set; }
//#if NETFRAMEWORK
/// <summary>
/// Validates whether the receiver and document data are complete.
/// </summary>
public List<string> ValidateReceiverDocumentData()
{
var errors = new List<string>();
if (!Documents?.Any() ?? true)
errors.Add(My.Resources.Envelope.Missing_Documents);
if (!EnvelopeReceivers?.Any() ?? true)
errors.Add(My.Resources.Envelope.Missing_Receivers);
if (EnvelopeReceivers?.Any(r => !r.HasEmailAndName) ?? false)
errors.Add(My.Resources.Envelope.Incomplete_Receivers);
return errors;
}
//#endif
}
#if NETFRAMEWORK
}
#endif