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