noti สำเนา

This commit is contained in:
kittapath 2024-10-19 22:29:44 +07:00
parent cf56ef9297
commit 33be7f1121
3 changed files with 82 additions and 0 deletions

View file

@ -334,6 +334,61 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
throw;
}
}
public class NotisLinkSendRequest
{
public Guid ReceiverUserId { get; set; }
public string NotiLink { get; set; }
public bool IsSendMail { get; set; }
public bool IsSendInbox { get; set; }
}
public async Task PushNotificationsLinkSendAsync(NotisLinkSendRequest[] ReceiverUserIds, string Subject, string Body, string Payload = "")
{
try
{
foreach (var data in ReceiverUserIds)
{
_dbContext.Set<Notification>().Add(new Notification
{
Body = Body,
ReceiverUserId = data.ReceiverUserId,
Type = "",
Payload = data.NotiLink,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
if (data.IsSendInbox == true)
{
_dbContext.Set<Inbox>().Add(new Inbox
{
Subject = Subject,
Body = Body,
ReceiverUserId = data.ReceiverUserId,
Payload = Payload,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
}
if (data.IsSendMail == true)
{
_emailSenderService.SendMail(Subject, Body, "kittapath@frappet.com");
}
}
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
public async Task PushNotificationAsyncV2(string? ReceiverUserId, string Subject, string Body, string Payload = "", bool IsSendInbox = false, bool IsSendMail = false)
{
try