source: ChapterX.Application/Chapter/Commands/UpdateHandler.cs@ a7550ca

main
Last change on this file since a7550ca was 877c13c, checked in by kikisrbinoska <srbinoskakristina07@…>, 4 months ago

Added files

  • Property mode set to 100644
File size: 1.2 KB
Line 
1using ChapterX.Domain.Repositories;
2using MediatR;
3using Microsoft.Extensions.Logging;
4
5namespace ChapterX.Application.Chapter.Commands
6{
7 public class UpdateHandler : IRequestHandler<UpdateRequest, UpdateResponse>
8 {
9 private readonly IChapterRepository _chapterRepository;
10 private readonly ILogger<UpdateHandler> _logger;
11
12 public UpdateHandler(IChapterRepository chapterRepository, ILogger<UpdateHandler> logger)
13 {
14 _chapterRepository = chapterRepository;
15 _logger = logger;
16 }
17
18 public async Task<UpdateResponse> Handle(UpdateRequest request, CancellationToken cancellationToken)
19 {
20 var chapter = await _chapterRepository.GetByIdAsync(request.Id, cancellationToken);
21 if (chapter is null)
22 return new UpdateResponse(false);
23
24 chapter.Number = request.Number;
25 chapter.Name = request.Name;
26 chapter.Title = request.Title;
27 chapter.Content = request.Content;
28 chapter.WordCount = request.WordCount;
29 chapter.UpdatedAt = DateTime.UtcNow;
30
31 await _chapterRepository.UpdateAsync(chapter, cancellationToken);
32
33 return new UpdateResponse(true);
34 }
35 }
36}
Note: See TracBrowser for help on using the repository browser.