Api/Brizco.Repository/MartenHandlers/Notifications/CreateNotificationHandlerCo...

24 lines
1.1 KiB
C#
Raw Normal View History

2024-07-31 10:18:38 +03:30
namespace Brizco.Repository.MartenHandlers.Notifications;
2024-07-31 10:18:38 +03:30
public class CreateNotificationHandlerCommand(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService)
: IRequestHandler<CreateNotificationCommand,Guid>
{
public async Task<Guid> Handle(CreateNotificationCommand request, CancellationToken cancellationToken)
{
2024-07-31 10:18:38 +03:30
if (currentUserService.ComplexId == null)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null");
2024-07-31 10:18:38 +03:30
if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId))
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong");
var notification = new Notification
{
Message = request.Message,
UserId = request.UserId,
ComplexId = complexId,
CreatedAt = DateTime.Now
};
2024-07-31 10:18:38 +03:30
await martenRepositoryWrapper.SetRepository<Notification>()
.AddOrUpdateEntityAsync(notification, cancellationToken);
return notification.Id;
}
}