public async ValueTask <ICommandResult> Handle(CadastrarModeloCommand command) { if (!command.Validate()) { AddNotifications(command); return(new CommandResult(false, base.Notifications)); } var marcaEntity = await _marcaRepository.GetById(command.MarcaId).ConfigureAwait(true); if (marcaEntity is null) { AddNotification("Marca", "Marca Nao Encontrada"); return(new CommandResult(false, base.Notifications)); } var entity = new Modelo(command.Nome, command.MarcaId); await _modeloRepository.Add(entity); var result = await _marcaRepository.SaveChanges().ConfigureAwait(true); if (!result) { return(new CommandResult(false)); } return(new CommandResult(true)); }
public async Task <IActionResult> CriarModeloAsync([FromBody] CadastrarModeloCommand command) { var result = await _command.Handle(command).ConfigureAwait(true) as CommandResult; if (result.Success) { return(Ok()); } else { return(UnprocessableEntity(result.Messages)); } }
public async Task <IActionResult> Post([FromBody] CadastrarModeloCommand command) { var id = await _mediator.Send(command); return(CreatedAtAction("Get", new { id }, command)); }