แก้ฟังก์ชันnoti ถ้าหาprofileไม่เจอให้ข้ามเลย

This commit is contained in:
Kittapath 2023-09-08 09:51:51 +07:00
parent b25f52761f
commit 7f53cf96c4
3 changed files with 50 additions and 50 deletions

View file

@ -59,58 +59,58 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
try
{
var profile = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.Id == ReceiverUserId);
if (profile == null)
throw new Exception(GlobalMessages.DataNotFound);
if (IsSendNotification == true)
if (profile != null)
{
_dbContext.Set<Notification>().Add(new Notification
if (IsSendNotification == true)
{
Body = Body,
ReceiverUserId = ReceiverUserId,
Type = "",
Payload = "",
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
}
if (IsSendInbox == true)
{
_dbContext.Set<Inbox>().Add(new Inbox
_dbContext.Set<Notification>().Add(new Notification
{
Body = Body,
ReceiverUserId = ReceiverUserId,
Type = "",
Payload = "",
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
}
if (IsSendInbox == true)
{
Subject = Subject,
Body = Body,
ReceiverUserId = ReceiverUserId,
Payload = "",
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
_dbContext.Set<Inbox>().Add(new Inbox
{
Subject = Subject,
Body = Body,
ReceiverUserId = ReceiverUserId,
Payload = "",
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
}
if (IsSendMail == true)
{
// _context.Notifications.Add(new Notification
// {
// Body = req.Body,
// ReceiverUserId = req.ReceiverUserId,
// Type = "",
// Payload = "",
// CreatedUserId = FullName ?? "",
// CreatedFullName = UserId ?? "System Administrator",
// CreatedAt = DateTime.Now,
// LastUpdateFullName = FullName ?? "System Administrator",
// LastUpdateUserId = UserId ?? "",
// LastUpdatedAt = DateTime.Now,
// });
}
await _dbContext.SaveChangesAsync();
}
if (IsSendMail == true)
{
// _context.Notifications.Add(new Notification
// {
// Body = req.Body,
// ReceiverUserId = req.ReceiverUserId,
// Type = "",
// Payload = "",
// CreatedUserId = FullName ?? "",
// CreatedFullName = UserId ?? "System Administrator",
// CreatedAt = DateTime.Now,
// LastUpdateFullName = FullName ?? "System Administrator",
// LastUpdateUserId = UserId ?? "",
// LastUpdatedAt = DateTime.Now,
// });
}
await _dbContext.SaveChangesAsync();
}
catch
{