main
|
Last change
on this file since a8f4a2d was 877c13c, checked in by kikisrbinoska <srbinoskakristina07@…>, 4 months ago |
|
Added files
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | using ChapterX.Domain.Repositories;
|
|---|
| 2 | using MediatR;
|
|---|
| 3 | using Microsoft.Extensions.Logging;
|
|---|
| 4 |
|
|---|
| 5 | namespace ChapterX.Application.Notification.Commands
|
|---|
| 6 | {
|
|---|
| 7 | public class UpdateHandler : IRequestHandler<UpdateRequest, UpdateResponse>
|
|---|
| 8 | {
|
|---|
| 9 | private readonly INotificationRepository _notificationRepository;
|
|---|
| 10 | private readonly ILogger<UpdateHandler> _logger;
|
|---|
| 11 |
|
|---|
| 12 | public UpdateHandler(INotificationRepository notificationRepository, ILogger<UpdateHandler> logger)
|
|---|
| 13 | {
|
|---|
| 14 | _notificationRepository = notificationRepository;
|
|---|
| 15 | _logger = logger;
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | public async Task<UpdateResponse> Handle(UpdateRequest request, CancellationToken cancellationToken)
|
|---|
| 19 | {
|
|---|
| 20 | var notification = await _notificationRepository.GetByIdAsync(request.Id, cancellationToken);
|
|---|
| 21 | if (notification is null)
|
|---|
| 22 | return new UpdateResponse(false);
|
|---|
| 23 |
|
|---|
| 24 | notification.Content = request.Content;
|
|---|
| 25 | notification.IsRead = request.IsRead;
|
|---|
| 26 |
|
|---|
| 27 | await _notificationRepository.UpdateAsync(notification, cancellationToken);
|
|---|
| 28 |
|
|---|
| 29 | return new UpdateResponse(true);
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.