187 lines
6.9 KiB
C#
187 lines
6.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using LCU.Library.Internal.MemberPreferencesApiModels.Enums;
|
|
using LCU.Library.Internal.MemberPreferencesApiModels.Models;
|
|
|
|
namespace LCU.Library.Internal.MemberPreferencesApiModels.Entities
|
|
{
|
|
public class MemberOptInSettings : Auditable
|
|
{
|
|
public MemberOptInSettings()
|
|
{
|
|
}
|
|
|
|
public int Id { get; set; }
|
|
public string UserId { get; set; }
|
|
public string EStatements { get; set; }
|
|
public string ENotifications { get; set; }
|
|
public string UniversalOptIn { get; set; }
|
|
public string LegalVersion { get; set; }
|
|
public DateTime? LegalDate { get; set; }
|
|
public string UnifiedOptInEmail { get; set; }
|
|
public EmailStatus? UnifiedOptInEmailStatus { get; set; }
|
|
public DateTime? UnifiedOptInEmailFirstSent { get; set; }
|
|
public DateTime? UnifiedOptInEmailLastSent { get; set; }
|
|
public int UnifiedOptInEmailStatusCount { get; set; } = 0;
|
|
public string EStatementsEmail { get; set; }
|
|
public EmailStatus? EStatementsEmailStatus { get; set; }
|
|
public DateTime? EStatementsEmailFirstSent { get; set; }
|
|
public DateTime? EStatementsEmailLastSent { get; set; }
|
|
public int EStatementsEmailStatusCount { get; set; } = 0;
|
|
public string ENotificationsEmail { get; set; }
|
|
public EmailStatus? ENotificationsEmailStatus { get; set; }
|
|
public DateTime? ENotificationsEmailFirstSent { get; set; }
|
|
public DateTime? ENotificationsEmailLastSent { get; set; }
|
|
public int ENotificationsEmailStatusCount { get; set; } = 0;
|
|
|
|
public void ApplyAll(IReadOnlyCollection<MemberPreference> memberPreferences)
|
|
{
|
|
Id = 0;
|
|
UserId = "";
|
|
EStatements = null;
|
|
ENotifications = null;
|
|
UniversalOptIn = null;
|
|
LegalVersion = null;
|
|
LegalDate = null;
|
|
UnifiedOptInEmail = null;
|
|
EStatementsEmail = null;
|
|
ENotificationsEmail = null;
|
|
|
|
if (memberPreferences != null && memberPreferences.Any())
|
|
{
|
|
UserId = memberPreferences.First().UserId;
|
|
foreach (var memberPreference in memberPreferences)
|
|
{
|
|
Apply(memberPreference);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Apply(MemberPreference memberPreference)
|
|
{
|
|
void ClearUnifiedOptInEmailTracking()
|
|
{
|
|
UnifiedOptInEmailStatus = null;
|
|
UnifiedOptInEmailFirstSent = null;
|
|
UnifiedOptInEmailLastSent = null;
|
|
UnifiedOptInEmailStatusCount = 0;
|
|
}
|
|
|
|
void ClearENotificationEmailTracking()
|
|
{
|
|
ENotificationsEmailStatus = null;
|
|
ENotificationsEmailFirstSent = null;
|
|
ENotificationsEmailLastSent = null;
|
|
ENotificationsEmailStatusCount = 0;
|
|
}
|
|
|
|
void ClearEStatementsEmailTracking()
|
|
{
|
|
EStatementsEmailStatus = null;
|
|
EStatementsEmailFirstSent = null;
|
|
EStatementsEmailLastSent = null;
|
|
EStatementsEmailStatusCount = 0;
|
|
}
|
|
|
|
switch (memberPreference.Preference)
|
|
{
|
|
case PreferenceType.UnifiedOptIn:
|
|
{
|
|
if (!memberPreference.Value.Equals(UniversalOptIn, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
ClearUnifiedOptInEmailTracking();
|
|
}
|
|
|
|
UniversalOptIn = memberPreference.Value;
|
|
LegalVersion = memberPreference.LegalReference;
|
|
LegalDate = DateTime.Now;
|
|
|
|
break;
|
|
}
|
|
case PreferenceType.UnifiedOptInEmail:
|
|
{
|
|
ClearUnifiedOptInEmailTracking();
|
|
UnifiedOptInEmail = memberPreference.Value;
|
|
|
|
break;
|
|
}
|
|
case PreferenceType.ENotification:
|
|
{
|
|
if (!memberPreference.Value.Equals(ENotifications, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
ClearENotificationEmailTracking();
|
|
}
|
|
|
|
ENotifications = memberPreference.Value;
|
|
|
|
break;
|
|
}
|
|
case PreferenceType.ENotificationsEmail:
|
|
{
|
|
ClearENotificationEmailTracking();
|
|
ENotificationsEmail = memberPreference.Value;
|
|
|
|
break;
|
|
}
|
|
case PreferenceType.EStatements:
|
|
{
|
|
if (!memberPreference.Value.Equals(EStatements, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
ClearEStatementsEmailTracking();
|
|
}
|
|
|
|
EStatements = memberPreference.Value;
|
|
|
|
break;
|
|
}
|
|
case PreferenceType.EStatementsEmail:
|
|
{
|
|
ClearEStatementsEmailTracking();
|
|
EStatementsEmail = memberPreference.Value;
|
|
|
|
break;
|
|
}
|
|
default:
|
|
throw new InvalidOperationException(
|
|
$"Unknown preference type update: {memberPreference.Preference}");
|
|
}
|
|
}
|
|
|
|
public bool IsUnifiedPaperEnrolled()
|
|
{
|
|
return string.Equals(UniversalOptIn, DeliveryPreference.Paper, StringComparison.InvariantCultureIgnoreCase);
|
|
}
|
|
|
|
public bool IsUnifiedElectronicEnrolled()
|
|
{
|
|
return string.Equals(UniversalOptIn, DeliveryPreference.Electronic, StringComparison.InvariantCultureIgnoreCase);
|
|
}
|
|
|
|
public bool HasAnyUnifiedPreference()
|
|
{
|
|
return !string.IsNullOrWhiteSpace(UniversalOptIn);
|
|
}
|
|
|
|
public bool IsOldNoticesElectronicEnrolled()
|
|
{
|
|
return string.Equals(ENotifications, DeliveryPreference.Electronic, StringComparison.InvariantCultureIgnoreCase);
|
|
}
|
|
|
|
public bool IsOldStatementsElectronicEnrolled()
|
|
{
|
|
return string.Equals(EStatements, DeliveryPreference.Electronic, StringComparison.InvariantCultureIgnoreCase);
|
|
}
|
|
|
|
public bool Compare(MemberOptInSettings other)
|
|
{
|
|
return other != null && other.ENotifications == ENotifications &&
|
|
other.EStatements == EStatements &&
|
|
other.UniversalOptIn == UniversalOptIn &&
|
|
other.UnifiedOptInEmail == UnifiedOptInEmail &&
|
|
other.EStatementsEmail == EStatementsEmail &&
|
|
other.ENotificationsEmail == ENotificationsEmail;
|
|
}
|
|
}
|
|
}
|