| 123456789101112131415161718192021222324252627282930313233 |
- using Diligent.WebAPI.Business.Interfaces;
- using Diligent.WebAPI.Host.Mediator.Notifications.Commands;
- using MediatR;
-
- namespace Diligent.WebAPI.Host.Mediator.Notifications.Handlers
- {
- public class AddNotificationHandler : IRequestHandler<AddNotificationCommand, Unit>
- {
- private readonly ICustomerService _customerService;
-
- public AddNotificationHandler(ICustomerService customerService)
- {
- _customerService = customerService;
- }
-
- public async Task<Unit> 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();
- }
- }
- }
|