public async Task <IActionResult> CriarMarcaAsync([FromBody] CadastrarMarcaCommand command) { var result = await _command.Handle(command).ConfigureAwait(true) as CommandResult; if (result.Success) { return(Ok()); } else { return(UnprocessableEntity(result.Messages)); } }
public async ValueTask <ICommandResult> Handle(CadastrarMarcaCommand command) { if (!command.Validate()) { AddNotifications(command); return(new CommandResult(false, base.Notifications)); } var entity = new Marca(command.Nome, command.Pais); await _marcaRepository.Add(entity); var result = await _marcaRepository.SaveChanges().ConfigureAwait(true); if (!result) { return(new CommandResult(false)); } return(new CommandResult(true)); }
public async Task <IActionResult> Post([FromBody] CadastrarMarcaCommand command) { var id = await _mediator.Send(command); return(CreatedAtAction("Get", new { id }, command)); }