namespace Brizco.Repository.MartenHandlers.Notifications; public class CreateNotificationHandlerCommand(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService) : IRequestHandler { public async Task Handle(CreateNotificationCommand request, CancellationToken cancellationToken) { if (currentUserService.ComplexId == null) throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null"); 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 }; await martenRepositoryWrapper.SetRepository() .AddOrUpdateEntityAsync(notification, cancellationToken); return notification.Id; } }