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.

DeleteNotificationHandler.cs 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Diligent.WebAPI.Business.Interfaces;
  2. using Diligent.WebAPI.Host.Exceptions;
  3. using Diligent.WebAPI.Host.Mediator.Notifications.Commands;
  4. using MediatR;
  5. namespace Diligent.WebAPI.Host.Mediator.Notifications.Handlers
  6. {
  7. public class DeleteNotificationHandler : IRequestHandler<DeleteNotificationCommand, Unit>
  8. {
  9. private readonly ICustomerRepository _customerRepository;
  10. public DeleteNotificationHandler(ICustomerRepository customerRepository)
  11. {
  12. _customerRepository = customerRepository;
  13. }
  14. public async Task<Unit> Handle(DeleteNotificationCommand request, CancellationToken cancellationToken)
  15. {
  16. var user = await _customerRepository.GetCustomerById(request.NotificationData.UserId);
  17. if (user == null)
  18. {
  19. throw new NotFoundException();
  20. }
  21. var notification = user.Notifications.Where(x => x.RoomId == request.NotificationData.RoomId).FirstOrDefault();
  22. if (notification == null)
  23. {
  24. throw new NotFoundException();
  25. }
  26. await _customerRepository.DeleteNotification(user, notification);
  27. return new Unit();
  28. }
  29. }
  30. }