Files
DigitalData.MessagingService/src/DigitalData.EmailProfiler.Domain/Entities/EmailProfile.cs
TekH 111d2bf264 fix(domain): use DateTime.Now instead of DateTime.UtcNow for legacy compatibility
CRITICAL FIX: Replace all DateTime.UtcNow with DateTime.Now throughout the application.

Reason: Legacy VB.NET system uses local server time, and database stores all
timestamps as local time. Using UTC breaks compatibility and causes incorrect
time comparisons.

Changes:
- EmailProcessedEvent: ProcessedDate now uses DateTime.Now
- EmailHistory.MarkAsProcessed(): ProcessedDate now uses DateTime.Now
- EmailHistory.MarkAsFailed(): ProcessedDate now uses DateTime.Now
- EmailProfile.UpdateLastPollTime(): LastPollTime now uses DateTime.Now
- EmailProfile.ShouldPoll(): Poll interval comparison now uses DateTime.Now

Documentation:
- Added critical note to agents.md about DateTime usage
- Includes examples and detailed explanation for future developers

This ensures all date/time operations remain compatible with legacy database.
2026-07-08 10:36:13 +02:00

89 lines
2.4 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using DigitalData.EmailProfiler.Domain.Common;
namespace DigitalData.EmailProfiler.Domain.Entities;
[Table("TBEMLP_POLL_PROFILES")]
public class EmailProfile : BaseEntity, IAggregateRoot
{
[Key]
[Column("GUID", Order = 0)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Column("PROFILE_NAME", TypeName = "varchar(100)")]
[Required]
[MaxLength(100)]
public string ProfileName { get; set; } = string.Empty;
[Column("POLL_TYPE", TypeName = "varchar(100)")]
[Required]
[MaxLength(100)]
public string PollType { get; set; } = "IMAP";
[Column("EMAIL_CONF_ID")]
[Required]
public int EmailAccountId { get; set; }
[Column("PROCESS_ID")]
public int? ProcessId { get; set; }
// Polling Configuration
[Column("POLL_INTERVAL")]
public int PollIntervalMinutes { get; set; } = 5;
[Column("LAST_TICK")]
public DateTime? LastPollTime { get; set; }
// Validation
[Column("VALIDATION_SQL", TypeName = "nvarchar(1024)")]
[MaxLength(1024)]
public string? ValidationSql { get; set; }
// Status
[Column("ACTIVE")]
public bool IsActive { get; set; }
[Column("SEQUENCE")]
public int? Sequence { get; set; }
[Column("COMMENT", TypeName = "varchar(500)")]
[MaxLength(500)]
public string? Comment { get; set; }
// Audit fields
[Column("ADDED_WHO", TypeName = "varchar(50)")]
[MaxLength(50)]
public string? AddedWho { get; set; }
[Column("ADDED_WHEN")]
public DateTime? AddedWhen { get; set; }
[Column("CHANGED_WHO", TypeName = "varchar(50)")]
[MaxLength(50)]
public string? ChangedWho { get; set; }
[Column("CHANGED_WHEN")]
public DateTime? ChangedWhen { get; set; }
// Navigation properties
[ForeignKey("EmailAccountId")]
public virtual EmailAccount? EmailAccount { get; set; }
[ForeignKey("ProcessId")]
public virtual EmailProcess? EmailProcess { get; set; }
public virtual ICollection<EmailHistory> EmailHistories { get; set; } = new List<EmailHistory>();
// Domain methods
public void UpdateLastPollTime() => LastPollTime = DateTime.Now;
public bool ShouldPoll()
{
if (!IsActive) return false;
if (!LastPollTime.HasValue) return true;
return DateTime.Now >= LastPollTime.Value.AddMinutes(PollIntervalMinutes);
}
}