api noti
This commit is contained in:
parent
6917e8e573
commit
0d6b4bee62
2 changed files with 127 additions and 0 deletions
112
BMA.EHR.Placement.Service/Controllers/NotifyController.cs
Normal file
112
BMA.EHR.Placement.Service/Controllers/NotifyController.cs
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Extensions;
|
||||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using BMA.EHR.Domain.Models.Notifications;
|
||||
using BMA.EHR.Domain.Models.Placement;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using BMA.EHR.Placement.Service.Requests;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace BMA.EHR.Placement.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/placement/noti")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("ระบบบรรจุ")]
|
||||
public class NotifyController : BaseController
|
||||
{
|
||||
private readonly PlacementRepository _repository;
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public NotifyController(PlacementRepository repository,
|
||||
ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_repository = repository;
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
||||
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||
|
||||
#endregion
|
||||
|
||||
[HttpPost()]
|
||||
public async Task<ActionResult<ResponseObject>> UpdatePropertyByUser([FromBody] NotiRequest req)
|
||||
{
|
||||
var profile = await _context.Profiles.FirstOrDefaultAsync(x => x.Id == req.ReceiverUserId);
|
||||
if (profile == null)
|
||||
return Error(GlobalMessages.DataNotFound);
|
||||
|
||||
if (req.IsSendInbox == true)
|
||||
{
|
||||
_context.Inboxes.Add(new Inbox
|
||||
{
|
||||
Subject = req.Subject,
|
||||
Body = req.Body,
|
||||
ReceiverUserId = req.ReceiverUserId,
|
||||
Payload = "",
|
||||
CreatedUserId = FullName ?? "",
|
||||
CreatedFullName = UserId ?? "System Administrator",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
}
|
||||
if (req.IsSendInbox == 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,
|
||||
});
|
||||
}
|
||||
if (req.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 _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue