public async ValueTask <ICommandResult> Handle(AgendarVeiculoCommand command) { if (!command.Validate()) { AddNotifications(command); return(new CommandResult(false, base.Notifications)); } var clienteEntity = await _clienteRepository.GetById(command.ClienteId).ConfigureAwait(true); var veiculoEntity = await _veiculoRepository.GetById(command.VeiculoId).ConfigureAwait(true); if (clienteEntity == null) { AddNotification("Cliente", "Cliente nao Encontrado."); return(new CommandResult(false, base.Notifications)); } if (veiculoEntity == null) { AddNotification("Veiculo", "Veiculo Nao Encontrado"); return(new CommandResult(false, base.Notifications)); } var agendamento = new Agendamento(command.CodigoAgencia, command.VeiculoId, command.DataAgendamento, command.ClienteId, command.Diarias); agendamento.GerarValorFinalAgendamento(veiculoEntity.ValorHora, veiculoEntity.Categoria, command.Diarias); veiculoEntity.Reservado = true; await _veiculoRepository.Update(veiculoEntity); await _veiculoRepository.SaveChanges().ConfigureAwait(true); await _AgendamentoRepository.Add(agendamento); await _AgendamentoRepository.SaveChanges().ConfigureAwait(true); var entidadeAgendamento = await _AgendamentoRepository.Search(x => x.VeiculoId == command.VeiculoId && x.ClientesId == command.ClienteId).ConfigureAwait(true); var result = entidadeAgendamento.FirstOrDefault(); return(new CommandResult(true, result)); }