Beispiel #1
0
        public Task <CommandResult> Handle(AddOrdemServicoCommand command, CancellationToken cancellationToken)
        {
            if (!command.IsValid())
            {
                NotifyCommandErrors(command);
                return(Response());
            }

            Cliente cliente = _clienteRepository.GetById(command.ClienteId);

            if (cliente == null)
            {
                NotifyCommandError("Cliente não encontrado", "Erro de repositório");
                return(Response());
            }

            OrdemServico ordemServico = new OrdemServico(cliente, command.Produtos);

            _ordemServicoRepository.Add(ordemServico);

            if (Commit())
            {
                _mediator.Publish(new AddedOrdemServicoEvent());
            }

            return(Response());
        }
Beispiel #2
0
 public async Task <ActionResult <CommandResult> > Post(
     [FromBody] AddOrdemServicoCommand command)
 {
     return(Ok((CommandResult)await _handler.Handle(command)));
 }