Int32 不实现 IRequest(参数"请求")



我正在尝试实现MediatrCQRS模式。我得到它的工作为Create命令和Get查询。但是当我试图运行带有参数的Delete命令时,我得到了这个错误

Int32没有实现IRequest (Parameter 'request')

这是我的代码。

public class DeleteMarketingEventCommand : IRequest<int>
{
public int Id{ get; }
public DeleteMarketingEventCommand(int id)
{
Id = id;
}
}
public class DeleteMarketingEventHandler : IRequestHandler<DeleteMarketingEventCommand, int>
{
private readonly IMarketingEventService _marketingEventService;
private readonly IMapper _mapper;
public DeleteMarketingEventHandler(IMapper mapper, IMarketingEventService marketingEventService)
{
_mapper = mapper;
_marketingEventService = marketingEventService;
}
public async Task<int> Handle(DeleteMarketingEventCommand request, CancellationToken cancellationToken)
{
var result = await _marketingEventService.DeleteMarketingEvent(request.Id);
return result;            
}
}
[HttpDelete]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult> DeleteMarketingEventById(int id)
{
try
{
var result = _mediator.Send(id);
return Ok(result);         
}
catch (Exception ex)
{
return Problem(ex.Message);
}
}

您需要传递DeleteMarketingEventCommand:

public async Task<ActionResult> DeleteMarketingEventById(int id)
{
try
{
var result = _mediator.Send(new DeleteMarketingEventCommand(id));
return Ok(result);         
}
catch (Exception ex)
{
return Problem(ex.Message);
}
}

public async Task<ActionResult> DeleteMarketingEventById(DeleteMarketingEventCommand command)
{
try
{
var result = _mediator.Send(command);
return Ok(result);         
}
catch (Exception ex)
{
return Problem(ex.Message);
}
}

相关内容

  • 没有找到相关文章

最新更新