public async ValueTask <ICommandResult> Handle(DevolverContratoCommand command)
        {
            if (!command.Validate())
            {
                AddNotifications(command);
                return(new CommandResult(false, base.Notifications));
            }

            var entityContrato = await _contratoRepository.GetById(command.ContratoId).ConfigureAwait(true);

            if (entityContrato is null)
            {
                AddNotification("Contrato", "Contrato nao Encontrado.");
                return(new CommandResult(false, base.Notifications));
            }

            var dadosDevolucao = new DadosDevolucao(command.CarroLimpo, command.TanqueCheio, command.Amassado, command.Arranhado, entityContrato.Id);
            await _devolucaoepository.Add(dadosDevolucao).ConfigureAwait(true);

            var result = await _devolucaoepository.SaveChanges().ConfigureAwait(true);

            if (!result)
            {
                AddNotification("Contrato", "Devolucao nao pode ser Registrada");
                return(new CommandResult(false, base.Notifications));
            }
            return(new CommandResult(true));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> DevolverReservaAsync(DevolverContratoCommand command)
        {
            var result = await _commandDevoler.Handle(command).ConfigureAwait(true) as CommandResult;

            if (result.Success)
            {
                return(Ok());
            }
            else
            {
                return(UnprocessableEntity());
            }
        }