2024-07-31 10:18:38 +03:30
|
|
|
|
namespace Brizco.Repository.MartenHandlers.Notifications;
|
2024-05-29 19:17:41 +03:30
|
|
|
|
|
2024-07-31 10:18:38 +03:30
|
|
|
|
public class CreateNotificationHandlerCommand(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService)
|
|
|
|
|
|
: IRequestHandler<CreateNotificationCommand,Guid>
|
2024-05-29 19:17:41 +03:30
|
|
|
|
{
|
|
|
|
|
|
public async Task<Guid> Handle(CreateNotificationCommand request, CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
2024-07-31 10:18:38 +03:30
|
|
|
|
if (currentUserService.ComplexId == null)
|
2024-05-29 19:17:41 +03:30
|
|
|
|
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))
|
2024-05-29 19:17:41 +03:30
|
|
|
|
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>()
|
2024-05-29 19:17:41 +03:30
|
|
|
|
.AddOrUpdateEntityAsync(notification, cancellationToken);
|
|
|
|
|
|
return notification.Id;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|