using Diligent.WebAPI.Business.Services; using Diligent.WebAPI.Host.Mediator.Notifications.Commands; using MediatR; namespace Diligent.WebAPI.Host.Mediator.Notifications.Handlers { public class AddNotificationHandler : IRequestHandler { private readonly ICustomerService _customerService; public AddNotificationHandler(ICustomerService customerService) { _customerService = customerService; } public async Task Handle(AddNotificationCommand request, CancellationToken cancellationToken) { if (request == null) { throw new BadHttpRequestException("Object cannot be null"); } var result = await _customerService.AddNotification(request.Notification.ReceiverId, request.Notification.RoomId); if (!result) { throw new Exception("Problem with saving notification in database"); } return new Unit(); } } }