diff --git a/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs b/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs index dfd0baf0..f3e461ea 100644 --- a/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs +++ b/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs @@ -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().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().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 diff --git a/BMA.EHR.Placement.Service/Controllers/NotifyController.cs b/BMA.EHR.Placement.Service/Controllers/NotifyController.cs index 6e6797a7..a602e408 100644 --- a/BMA.EHR.Placement.Service/Controllers/NotifyController.cs +++ b/BMA.EHR.Placement.Service/Controllers/NotifyController.cs @@ -135,6 +135,18 @@ namespace BMA.EHR.Placement.Service.Controllers return Success(); } + [HttpPost("profiles-send")] + public async Task> UpdatePropertyByUserProfiles_send([FromBody] NotisSendRequest req) + { + await _repositoryNoti.PushNotificationsLinkSendAsync( + req.ReceiverUserIds, + req.Subject, + req.Body, + req.Payload + ); + return Success(); + } + [HttpPut("{id:length(36)}")] public async Task> ReplyPropertyByUser([FromBody] NotiReplyRequest req, Guid id) { diff --git a/BMA.EHR.Placement.Service/Requests/NotisSendRequest.cs b/BMA.EHR.Placement.Service/Requests/NotisSendRequest.cs new file mode 100644 index 00000000..d0911e1d --- /dev/null +++ b/BMA.EHR.Placement.Service/Requests/NotisSendRequest.cs @@ -0,0 +1,15 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; +using static BMA.EHR.Application.Repositories.MessageQueue.NotificationRepository; + +namespace BMA.EHR.Placement.Service.Requests +{ + public class NotisSendRequest + { + public string Subject { get; set; } + public string Body { get; set; } + public string Payload { get; set; } + // public string NotiLink { get; set; } + public NotisLinkSendRequest[] ReceiverUserIds { get; set; } + } +}