You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AddNotificationHandler.cs 1.0KB

123456789101112131415161718192021222324252627282930313233
  1. using Diligent.WebAPI.Business.Interfaces;
  2. using Diligent.WebAPI.Host.Mediator.Notifications.Commands;
  3. using MediatR;
  4. namespace Diligent.WebAPI.Host.Mediator.Notifications.Handlers
  5. {
  6. public class AddNotificationHandler : IRequestHandler<AddNotificationCommand, Unit>
  7. {
  8. private readonly ICustomerService _customerService;
  9. public AddNotificationHandler(ICustomerService customerService)
  10. {
  11. _customerService = customerService;
  12. }
  13. public async Task<Unit> Handle(AddNotificationCommand request, CancellationToken cancellationToken)
  14. {
  15. if (request == null)
  16. {
  17. throw new BadHttpRequestException("Object cannot be null");
  18. }
  19. var result = await _customerService.AddNotification(request.Notification.ReceiverId, request.Notification.RoomId);
  20. if (!result)
  21. {
  22. throw new Exception("Problem with saving notification in database");
  23. }
  24. return new Unit();
  25. }
  26. }
  27. }