DeleteNetActionPropertysCommandHandler.cs
1.46 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
45
46
using MassTransit;
using Microsoft.Extensions.Logging;
using Rcs.Application.Common;
using Rcs.Application.MessageBus.Commands;
using Rcs.Domain.Repositories;
namespace Rcs.Infrastructure.MessageBus.Handlers.Commands;
/// <summary>
/// 删除网络动作属性命令处理器
/// @author zzy
/// </summary>
public class DeleteNetActionPropertysCommandHandler : IConsumer<DeleteNetActionPropertysCommand>
{
private readonly ILogger<DeleteNetActionPropertysCommandHandler> _logger;
private readonly INetActionPropertysRepository _repository;
public DeleteNetActionPropertysCommandHandler(
ILogger<DeleteNetActionPropertysCommandHandler> logger,
INetActionPropertysRepository repository)
{
_logger = logger;
_repository = repository;
}
public async Task Consume(ConsumeContext<DeleteNetActionPropertysCommand> context)
{
var command = context.Message;
try
{
var entity = await _repository.GetByIdAsync(command.NetActionId, context.CancellationToken);
if (entity == null)
{
throw new InvalidOperationException($"网络动作属性ID {command.NetActionId} 不存在");
}
await _repository.DeleteByIdAsync(command.NetActionId);
await context.RespondAsync(ApiResponse.Successful());
}
catch (Exception ex)
{
await context.RespondAsync(ApiResponse.Failed(ex.Message));
}
}
}