Refactoring EmailMessage, EmailRecipient, MessageSenderService, etc...
This commit is contained in:
parent
a8b4c2cb23
commit
a05153b267
|
|
@ -10,4 +10,8 @@
|
||||||
<ProjectReference Include="..\AyCode.Interfaces\AyCode.Interfaces.csproj" />
|
<ProjectReference Include="..\AyCode.Interfaces\AyCode.Interfaces.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Messages\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Net.Mail;
|
||||||
|
using AyCode.Interfaces.Messages;
|
||||||
|
|
||||||
|
namespace AyCode.Entities.Messages;
|
||||||
|
|
||||||
|
[Table("EmailMessage")]
|
||||||
|
public abstract class AcEmailMessage<TEmailRecipient> : IAcEmailMessage<TEmailRecipient> where TEmailRecipient : IAcEmailRecipientBase
|
||||||
|
{
|
||||||
|
protected AcEmailMessage()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AcEmailMessage(Guid id, Guid? senderId, Guid contextId, string subject, string? text, string emailAddress) : this()
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
SenderId = senderId;
|
||||||
|
ContextId = contextId;
|
||||||
|
Subject = subject;
|
||||||
|
Text = text;
|
||||||
|
EmailAddress = emailAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public Guid ContextId { get; set; }
|
||||||
|
public Guid? SenderId { get; set; }
|
||||||
|
|
||||||
|
public virtual List<TEmailRecipient> Recipients { get; set; } = [];
|
||||||
|
|
||||||
|
[MaxLength(150)]
|
||||||
|
public string EmailAddress { get; set; }
|
||||||
|
[MaxLength(100)]
|
||||||
|
public string Subject { get; set; }
|
||||||
|
public string? Text { get; set; }
|
||||||
|
|
||||||
|
public DateTime Created { get; set; }
|
||||||
|
public DateTime Modified { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Net.Mail;
|
||||||
|
using AyCode.Interfaces.Messages;
|
||||||
|
|
||||||
|
namespace AyCode.Entities.Messages;
|
||||||
|
|
||||||
|
[Table("EmailRecipient")]
|
||||||
|
public abstract class AcEmailRecipient<TEmailMessage> : IAcEmailRecipient<TEmailMessage> where TEmailMessage : IAcEmailMessageBase
|
||||||
|
{
|
||||||
|
protected AcEmailRecipient()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AcEmailRecipient(Guid id, Guid recipientId, Guid emailMessageId, string emailAddress) : this()
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
RecipientId = recipientId;
|
||||||
|
EmailMessageId = emailMessageId;
|
||||||
|
EmailAddress = emailAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public Guid RecipientId { get; set; }
|
||||||
|
public Guid EmailMessageId { get; set; }
|
||||||
|
public string EmailAddress { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public virtual TEmailMessage EmailMessage { get; set; }
|
||||||
|
|
||||||
|
public DateTime Created { get; set; }
|
||||||
|
public DateTime Modified { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using AyCode.Interfaces.Messages;
|
|
||||||
|
|
||||||
namespace AyCode.Entities.Messages
|
|
||||||
{
|
|
||||||
//[Table("Notices")]
|
|
||||||
//public class NoticeBase : INoticeBase
|
|
||||||
//{
|
|
||||||
|
|
||||||
// public NoticeBase() { }
|
|
||||||
|
|
||||||
// public NoticeBase(Guid senderId, Guid receiverId, string message) : this(Guid.NewGuid(), senderId, receiverId, message) { }
|
|
||||||
// public NoticeBase(Guid id, Guid senderId, Guid receiverId, string message) : this()
|
|
||||||
// {
|
|
||||||
// Id = id;
|
|
||||||
// SenderId = senderId;
|
|
||||||
// ReceiverId = receiverId;
|
|
||||||
// Message = message;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
|
||||||
// public Guid Id { get; set; }
|
|
||||||
// public Guid SenderId { get; set; }
|
|
||||||
|
|
||||||
// public Guid ReceiverId { get; set; }
|
|
||||||
|
|
||||||
// public string Message { get; set; }
|
|
||||||
|
|
||||||
// public DateTime Created { get; set; }
|
|
||||||
// public DateTime Modified { get; set; }
|
|
||||||
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace AyCode.Interfaces.Messages;
|
||||||
|
|
||||||
|
public interface IAcEmailMessage<TEmailRecipient> : IAcEmailMessageBase, IAcEmailRecipientsRelation<TEmailRecipient>
|
||||||
|
where TEmailRecipient : IAcEmailRecipientBase
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
using AyCode.Interfaces.Entities;
|
||||||
|
using AyCode.Interfaces.TimeStampInfo;
|
||||||
|
using AyCode.Interfaces.Users;
|
||||||
|
|
||||||
|
namespace AyCode.Interfaces.Messages;
|
||||||
|
|
||||||
|
public interface IAcEmailMessageBase : IEntityGuid, ITimeStampInfo, IAcEmailAddress
|
||||||
|
{
|
||||||
|
|
||||||
|
public Guid ContextId { get; set; }
|
||||||
|
public Guid? SenderId { get; set; }
|
||||||
|
|
||||||
|
public string Subject { get; set; }
|
||||||
|
public string? Text { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
namespace AyCode.Interfaces.Messages;
|
||||||
|
|
||||||
|
public interface IAcEmailMessageRelation<TEmailMessage> where TEmailMessage : IAcEmailMessageBase
|
||||||
|
{
|
||||||
|
TEmailMessage EmailMessage { get; }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
using System.Net.Mail;
|
||||||
|
|
||||||
|
namespace AyCode.Interfaces.Messages;
|
||||||
|
|
||||||
|
public interface IAcEmailRecipient<TEmailMessage> : IAcEmailRecipientBase, IAcEmailMessageRelation<TEmailMessage>
|
||||||
|
where TEmailMessage : IAcEmailMessageBase
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
using AyCode.Interfaces.Entities;
|
||||||
|
using AyCode.Interfaces.TimeStampInfo;
|
||||||
|
using AyCode.Interfaces.Users;
|
||||||
|
|
||||||
|
namespace AyCode.Interfaces.Messages;
|
||||||
|
|
||||||
|
public interface IAcEmailRecipientBase : IEntityGuid, ITimeStampInfo, IAcEmailAddress
|
||||||
|
{
|
||||||
|
public Guid RecipientId { get; set; }
|
||||||
|
public Guid EmailMessageId { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
namespace AyCode.Interfaces.Messages;
|
||||||
|
|
||||||
|
public interface IAcEmailRecipientsRelation<TEmailRecipient>
|
||||||
|
{
|
||||||
|
public List<TEmailRecipient> Recipients { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
namespace AyCode.Interfaces.Messages;
|
||||||
|
|
||||||
|
public interface IAcMessageSenderService<TEmailMessage, TEmailRecipient>
|
||||||
|
where TEmailMessage : IAcEmailMessage<TEmailRecipient>
|
||||||
|
where TEmailRecipient : IAcEmailRecipientBase
|
||||||
|
{
|
||||||
|
public Task<string> SendMessageAsync(TEmailMessage message, int messageType);
|
||||||
|
}
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
|
|
||||||
namespace AyCode.Interfaces.Messages
|
|
||||||
{
|
|
||||||
public interface IMessageParticipants : IMessageSender, IMessageReceiver
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
using AyCode.Interfaces.Entities;
|
|
||||||
|
|
||||||
namespace AyCode.Interfaces.Messages
|
|
||||||
{
|
|
||||||
public interface IMessageReceiver : IEntityGuid
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
|
|
||||||
using AyCode.Interfaces.Entities;
|
|
||||||
|
|
||||||
namespace AyCode.Interfaces.Messages
|
|
||||||
{
|
|
||||||
public interface IMessageSender : IEntityGuid
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
using AyCode.Interfaces.Enums;
|
|
||||||
|
|
||||||
namespace AyCode.Interfaces.Messages
|
|
||||||
{
|
|
||||||
//public interface IMessageSenderService
|
|
||||||
//{
|
|
||||||
// public Task<string> SendMessageAsync<TNotice>(TNotice message, int messageType) where TNotice : class, ;
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
|
|
||||||
using AyCode.Interfaces.Entities;
|
|
||||||
using AyCode.Interfaces.Enums;
|
|
||||||
using AyCode.Interfaces.TimeStampInfo;
|
|
||||||
|
|
||||||
namespace AyCode.Interfaces.Messages
|
|
||||||
{
|
|
||||||
//public interface INoticeBase : IEntityGuid, ITimeStampInfo, IMessageParticipants
|
|
||||||
//{
|
|
||||||
// string Message { get; }
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,7 @@ using System.IO;
|
||||||
|
|
||||||
namespace AyCode.Interfaces.Users;
|
namespace AyCode.Interfaces.Users;
|
||||||
|
|
||||||
public interface IEmailAddress
|
public interface IAcEmailAddress
|
||||||
{
|
{
|
||||||
[MaxLength(150)]
|
[MaxLength(150)]
|
||||||
string EmailAddress { get; set; }
|
string EmailAddress { get; set; }
|
||||||
|
|
@ -4,7 +4,7 @@ using AyCode.Interfaces.TimeStampInfo;
|
||||||
|
|
||||||
namespace AyCode.Interfaces.Users;
|
namespace AyCode.Interfaces.Users;
|
||||||
|
|
||||||
public interface IAcUserBase : IEntityGuid, IAcProfileForeignKey, IEmailAddress, IEmailConfirmed, IPassword, ITimeStampInfo
|
public interface IAcUserBase : IEntityGuid, IAcProfileForeignKey, IAcEmailAddress, IEmailConfirmed, IPassword, ITimeStampInfo
|
||||||
{
|
{
|
||||||
public string? PhoneNumber { get; set; }
|
public string? PhoneNumber { get; set; }
|
||||||
public string? RefreshToken { get; set; }
|
public string? RefreshToken { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,13 @@ public interface IAcEmailServiceServer
|
||||||
}
|
}
|
||||||
public class AcEmailServiceServer() : IAcEmailServiceServer
|
public class AcEmailServiceServer() : IAcEmailServiceServer
|
||||||
{
|
{
|
||||||
private IConfiguration _configuration;
|
|
||||||
private readonly SendGridClient _sendGridClient;
|
private readonly SendGridClient _sendGridClient;
|
||||||
private readonly EmailAddress _fromEmailAddress;
|
private readonly EmailAddress _fromEmailAddress;
|
||||||
|
|
||||||
public AcEmailServiceServer(IConfiguration configuration) : this()
|
public AcEmailServiceServer(IConfiguration configuration) : this()
|
||||||
{
|
{
|
||||||
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
|
_sendGridClient = new SendGridClient(configuration["SendGrid:Key"]);
|
||||||
//_sendGridClient = new SendGridClient(_configuration.ServerUserName);
|
_fromEmailAddress = new EmailAddress(configuration["SendGrid:FromEmail"], configuration["SendGrid:FromName"]);
|
||||||
//_fromEmailAddress = new EmailAddress(_configuration.FromEmail, _configuration.FromName);
|
|
||||||
|
|
||||||
//Console.WriteLine($"{config.ServerUserName}; {config.FromEmail}; {config.FromName}");
|
//Console.WriteLine($"{config.ServerUserName}; {config.FromEmail}; {config.FromName}");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue