-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateTopicCommandHandler.cs
More file actions
44 lines (38 loc) · 1.39 KB
/
CreateTopicCommandHandler.cs
File metadata and controls
44 lines (38 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using CCE.Application.Common;
using CCE.Application.Common.Interfaces;
using CCE.Application.Community.Dtos;
using CCE.Application.Community.Queries.ListTopics;
using CCE.Application.Messages;
using CCE.Domain.Community;
using MediatR;
namespace CCE.Application.Community.Commands.CreateTopic;
public sealed class CreateTopicCommandHandler : IRequestHandler<CreateTopicCommand, Response<TopicDto>>
{
private readonly IRepository<Topic, System.Guid> _repo;
private readonly ICceDbContext _db;
private readonly MessageFactory _messages;
public CreateTopicCommandHandler(
IRepository<Topic, System.Guid> repo,
ICceDbContext db,
MessageFactory messages)
{
_repo = repo;
_db = db;
_messages = messages;
}
public async Task<Response<TopicDto>> Handle(CreateTopicCommand request, CancellationToken cancellationToken)
{
var topic = Topic.Create(
request.NameAr,
request.NameEn,
request.DescriptionAr,
request.DescriptionEn,
request.Slug,
request.ParentId,
request.IconUrl,
request.OrderIndex);
await _repo.AddAsync(topic, cancellationToken).ConfigureAwait(false);
await _db.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
return _messages.Ok(ListTopicsQueryHandler.MapToDto(topic), "CONTENT_CREATED");
}
}