Added package management
This commit is contained in:
@@ -6,15 +6,21 @@ public class CreateNotificationCommand : IRequest<Result<Guid>>
|
||||
{
|
||||
public NotificationDirection Direction { get; set; }
|
||||
|
||||
public string? Author { get; set; }
|
||||
public string? Sender { get; set; }
|
||||
|
||||
public string? Title { get; set; }
|
||||
public string? SenderAddress { get; set; }
|
||||
|
||||
public string? Description { get; set; }
|
||||
public string? Subject { get; set; }
|
||||
|
||||
public string? Message { get; set; }
|
||||
|
||||
public NotificationPlatforms Platform { get; set; }
|
||||
|
||||
public string? PlatformAddress { get; set; }
|
||||
public Priorities Priority { get; set; }
|
||||
|
||||
public string? Recipient { get; set; }
|
||||
|
||||
public string? RecipientAddress { get; set; }
|
||||
|
||||
public string? CorrelationId { get; set; }
|
||||
|
||||
@@ -22,39 +28,48 @@ public class CreateNotificationCommand : IRequest<Result<Guid>>
|
||||
|
||||
public bool IsInternal { get; set; }
|
||||
|
||||
private CreateNotificationCommand(NotificationDirection direction, string author, string title, string description, NotificationPlatforms platform, string platformAddress, string correlationId, string correlationIdType, bool isInternal)
|
||||
public bool IsHtml { get; set; }
|
||||
|
||||
private CreateNotificationCommand(NotificationDirection direction, string sender, string senderAddress, string subject, string message, NotificationPlatforms platform, Priorities priority, string recipient, string recipientAddress, string correlationId, string correlationIdType, bool isInternal, bool isHtml = false)
|
||||
{
|
||||
Direction = direction;
|
||||
Author = author;
|
||||
Title = title;
|
||||
Description = description;
|
||||
Sender = sender;
|
||||
SenderAddress = senderAddress;
|
||||
Subject = subject;
|
||||
Message = message;
|
||||
Platform = platform;
|
||||
PlatformAddress = platformAddress;
|
||||
Priority = priority;
|
||||
Recipient = recipient;
|
||||
RecipientAddress = recipientAddress;
|
||||
CorrelationId = correlationId;
|
||||
CorrelationIdType = correlationIdType;
|
||||
IsInternal = isInternal;
|
||||
IsHtml = isHtml;
|
||||
}
|
||||
|
||||
public static CreateNotificationCommand Create(NotificationDirection direction, string author, string title, string description, NotificationPlatforms platform, string platformAddress, string correlationId, string correlationIdType, bool isInternal)
|
||||
public static CreateNotificationCommand Create(NotificationDirection direction, string sender, string senderAddress, string subject, string message, NotificationPlatforms platform, Priorities priority, string recipient, string recipientAddress, string correlationId, string correlationIdType, bool isInternal, bool isHtml = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(author))
|
||||
throw new ArgumentException("Author cannot be null or whitespace.", nameof(author));
|
||||
if (string.IsNullOrWhiteSpace(sender))
|
||||
throw new ArgumentException("Sender name is required.", nameof(sender));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(title))
|
||||
throw new ArgumentException("Title cannot be null or whitespace.", nameof(title));
|
||||
if (string.IsNullOrWhiteSpace(subject))
|
||||
throw new ArgumentException("Subject is required.", nameof(subject));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(description))
|
||||
throw new ArgumentException("Description cannot be null or whitespace.", nameof(description));
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
throw new ArgumentException("Message is required.", nameof(message));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(platformAddress))
|
||||
throw new ArgumentException("PlatformAddress cannot be null or whitespace.", nameof(platformAddress));
|
||||
if (string.IsNullOrWhiteSpace(recipient))
|
||||
throw new ArgumentException("Recipient name is required.", nameof(recipient));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(recipientAddress))
|
||||
throw new ArgumentException("Recipient address is required.", nameof(recipientAddress));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(correlationId))
|
||||
throw new ArgumentException("CorrelationId cannot be null or whitespace.", nameof(correlationId));
|
||||
throw new ArgumentException("CorrelationId is required.", nameof(correlationId));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(correlationIdType))
|
||||
throw new ArgumentException("CorrelationIdType cannot be null or whitespace.", nameof(correlationIdType));
|
||||
throw new ArgumentException("CorrelationIdType is required.", nameof(correlationIdType));
|
||||
|
||||
return new(direction, author, title, description, platform, platformAddress, correlationId, correlationIdType, isInternal);
|
||||
return new(direction, sender, senderAddress, subject, message, platform, priority, recipient, recipientAddress, correlationId, correlationIdType, isInternal, isHtml);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-10
@@ -6,29 +6,34 @@ public class CreateNotificationCommandHandler(IDbContextFactory<ShopDbContext> c
|
||||
{
|
||||
public async ValueTask<Result<Guid>> Handle(CreateNotificationCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||
|
||||
var newNotification = context.Notifications.Add(new Entities.Notification
|
||||
{
|
||||
Direction = request.Direction,
|
||||
Sender = request.Author,
|
||||
Subject = request.Title,
|
||||
Message = request.Description,
|
||||
SenderName = request.Sender,
|
||||
Sender = request.SenderAddress,
|
||||
Recipient = request.Recipient,
|
||||
RecipientAddress = request.RecipientAddress,
|
||||
Subject = request.Subject,
|
||||
Message = request.Message,
|
||||
Platform = request.Platform,
|
||||
Recipient = request.PlatformAddress,
|
||||
Priority = request.Priority,
|
||||
CorrelationId = request.CorrelationId,
|
||||
CorrelationIdType = request.CorrelationIdType,
|
||||
IsInternal = request.IsInternal,
|
||||
IsHtml = request.IsHtml,
|
||||
Processed = false
|
||||
});
|
||||
|
||||
return newNotification is not null
|
||||
? Result.Ok(newNotification.Entity.Id)
|
||||
return newNotification is not null
|
||||
? Result.Ok(newNotification.Entity.Id)
|
||||
: Result.Fail(new Error("Failed to create notification"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user