using Brizco.Domain.MartenEntities.Notifications; namespace Brizco.Repository.MartenHandlers.Notifications; public class CreateNotificationHandlerCommand : IRequestHandler { private readonly IMartenRepositoryWrapper _martenRepositoryWrapper; private readonly ICurrentUserService _currentUserService; public CreateNotificationHandlerCommand(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService) { _martenRepositoryWrapper = martenRepositoryWrapper; _currentUserService = currentUserService; } 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; } }