Add helper methods for color conversion and string checksum generation
- Implemented ToColor extension method to convert predefined ColorType enums to HTML hex colors. - Added GetChecksum extension method to generate a SHA-256 checksum from a string. - Included conditional directive for .NET Framework compatibility.
This commit is contained in:
parent
39cc30f48b
commit
39c1d3e624
@ -1,7 +1,6 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using DigitalData.Modules.Base;
|
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -80,11 +79,11 @@ namespace EnvelopeGenerator.Domain.Entities
|
|||||||
SignedDate == DateTime.MinValue ? "-" : SignedDate.ToString("G");
|
SignedDate == DateTime.MinValue ? "-" : SignedDate.ToString("G");
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Color Color => Helpers.ColorTypeToColor(ColorType);
|
public Color Color => ColorType.ToColor();
|
||||||
|
|
||||||
public string GetSignature()
|
public string GetSignature()
|
||||||
{
|
{
|
||||||
return StringEx.GetChecksum(EmailAddress?.ToUpperInvariant() ?? string.Empty);
|
return EmailAddress.ToUpperInvariant().GetChecksum();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DigitalData.EmailProfilerDispatcher.Abstraction.Attributes" Version="1.0.0" />
|
<PackageReference Include="DigitalData.EmailProfilerDispatcher.Abstraction.Attributes" Version="1.0.0" />
|
||||||
<PackageReference Include="DigitalData.Modules.Base" Version="1.3.8" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
48
EnvelopeGenerator.Domain/Helpers.cs
Normal file
48
EnvelopeGenerator.Domain/Helpers.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
using System.Text;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
#if NETFRAMEWORK
|
||||||
|
using System;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.Domain
|
||||||
|
{
|
||||||
|
public static class Helpers
|
||||||
|
{
|
||||||
|
public static Color ToColor(this Constants.ColorType pColorType)
|
||||||
|
{
|
||||||
|
switch (pColorType)
|
||||||
|
{
|
||||||
|
case Constants.ColorType.ReceiverColor1:
|
||||||
|
return ColorTranslator.FromHtml("#22c55e");
|
||||||
|
case Constants.ColorType.ReceiverColor2:
|
||||||
|
return ColorTranslator.FromHtml("#3b82f6");
|
||||||
|
case Constants.ColorType.ReceiverColor3:
|
||||||
|
return ColorTranslator.FromHtml("#8b5cf6");
|
||||||
|
case Constants.ColorType.ReceiverColor4:
|
||||||
|
return ColorTranslator.FromHtml("#f59e0b");
|
||||||
|
case Constants.ColorType.ReceiverColor5:
|
||||||
|
return ColorTranslator.FromHtml("#ef4444");
|
||||||
|
case Constants.ColorType.ReceiverColor6:
|
||||||
|
return ColorTranslator.FromHtml("#14b8a6");
|
||||||
|
case Constants.ColorType.ReceiverColor7:
|
||||||
|
return ColorTranslator.FromHtml("#d946ef");
|
||||||
|
case Constants.ColorType.ReceiverColor8:
|
||||||
|
return ColorTranslator.FromHtml("#06b6d4");
|
||||||
|
case Constants.ColorType.ReceiverColor9:
|
||||||
|
return ColorTranslator.FromHtml("#10b981");
|
||||||
|
case Constants.ColorType.ReceiverColor10:
|
||||||
|
return ColorTranslator.FromHtml("#84cc16");
|
||||||
|
default:
|
||||||
|
return Color.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetChecksum(this string pStringToCheck)
|
||||||
|
{
|
||||||
|
byte[] bytes = Encoding.UTF8.GetBytes(pStringToCheck);
|
||||||
|
byte[] pChecksum = SHA256.Create().ComputeHash(bytes);
|
||||||
|
return BitConverter.ToString(pChecksum).Replace("-", "").ToLowerInvariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user