no message

This commit is contained in:
Kittapath 2024-05-21 14:31:29 +07:00
parent 2a17eff17d
commit fb6a83b36a
11 changed files with 17862 additions and 70 deletions

View file

@ -41,17 +41,17 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
{
try
{
var profile = await _dbContext.Set<Profile>()
.FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!));
// var profile = await _dbContext.Set<Profile>()
// .FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!));
if (profile == null)
{
return new List<NotificationResponse>();
// throw new Exception(GlobalMessages.DataNotFound);
}
// if (profile == null)
// {
// return new List<NotificationResponse>();
// // throw new Exception(GlobalMessages.DataNotFound);
// }
var data_search = await _dbContext.Set<Notification>()
.Where(x => x.ReceiverUserId == profile.Id)
.Where(x => x.KeycloakUserId == UserId)
.Where(x => x.DeleteDate == null)
.OrderByDescending(x => x.ReceiveDate)
.ToListAsync();
@ -64,6 +64,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
Id = x.Id,
Body = x.Body,
ReceiverUserId = x.ReceiverUserId,
KeycloakUserId = x.KeycloakUserId,
IsOpen = x.IsOpen,
Type = x.Type,
ReceiveDate = x.ReceiveDate,
@ -72,7 +73,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
}).ToList();
var data_opens = await _dbContext.Set<Notification>()
.Where(x => x.ReceiverUserId == profile.Id)
.Where(x => x.KeycloakUserId == UserId)
.Where(x => x.DeleteDate == null)
.OrderByDescending(x => x.ReceiveDate)
.Skip((page - 1) * pageSize)
@ -99,16 +100,16 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
{
try
{
var profile = await _dbContext.Set<Profile>()
.FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!));
// var profile = await _dbContext.Set<Profile>()
// .FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!));
if (profile == null)
{
return 0;
}
// if (profile == null)
// {
// return 0;
// }
var data_search = await _dbContext.Set<Notification>()
.Where(x => x.ReceiverUserId == profile.Id)
.Where(x => x.KeycloakUserId == UserId)
.Where(x => x.DeleteDate == null)
.Where(x => x.IsOpen == false)
.OrderByDescending(x => x.ReceiveDate)
@ -190,6 +191,53 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
throw;
}
}
public async Task PushNotificationAsyncV2(string? ReceiverUserId, string Subject, string Body, string Payload = "", bool IsSendInbox = false, bool IsSendMail = false)
{
try
{
if (ReceiverUserId != null)
{
_dbContext.Set<Notification>().Add(new Notification
{
Body = Body,
KeycloakUserId = ReceiverUserId,
Type = "",
Payload = Payload,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
if (IsSendInbox == true)
{
_dbContext.Set<Inbox>().Add(new Inbox
{
Subject = Subject,
Body = Body,
KeycloakUserId = ReceiverUserId,
Payload = Payload,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
}
if (IsSendMail == true)
{
_emailSenderService.SendMail(Subject, Body, "kittapath@frappet.com");
}
await _dbContext.SaveChangesAsync();
}
}
catch
{
throw;
}
}
#endregion
}