예제 #1
0
        public async Task <IActionResult> DevolverVeiculo(DevolucaoInputModel devolucaoInput, CancellationToken ctx)
        {
            var result = await _veiculoApplication.DevolverVeiculo(devolucaoInput, ctx);

            if (result.Valid)
            {
                return(Ok(result.Object));
            }

            return(UnprocessableEntity(result.Notifications));
        }
        /// <summary>
        /// Realiza a devolução do veiculo
        /// </summary>
        /// <param name="devolucaoInput"></param>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public async Task <Result <DevolucaoOutputModel> > DevolverVeiculo(DevolucaoInputModel devolucaoInput, CancellationToken ctx)
        {
            if (string.IsNullOrEmpty(devolucaoInput.CodigoReserva))
            {
                var notification = new List <Notification> {
                    new Notification(nameof(devolucaoInput.CodigoReserva), MensagensInfo.Veiculo_ReservaInvalida)
                };
                return(Result <DevolucaoOutputModel> .Error(notification));
            }

            if (string.IsNullOrEmpty(devolucaoInput.Placa))
            {
                var notification = new List <Notification> {
                    new Notification(nameof(devolucaoInput.Placa), MensagensInfo.Veiculo_PlacaInvalida)
                };
                return(Result <DevolucaoOutputModel> .Error(notification));
            }

            var agendamento = await _agendamentoRepository.ObterPorReserva(devolucaoInput.CodigoReserva, ctx);

            if (agendamento == null)
            {
                var notification = new List <Notification> {
                    new Notification(nameof(Agendamento), MensagensInfo.Veiculo_ReservaNaoEncontrada)
                };
                return(Result <DevolucaoOutputModel> .Error(notification));
            }

            var valorTotal30PorCento = Math.Round((30.0 / 100.0) * agendamento.ValorTotalAluguel, 2);

            var valorAdicional = devolucaoInput.ItensVistoria.Amassados ? valorTotal30PorCento : 0;

            valorAdicional = devolucaoInput.ItensVistoria.Arranhoes ? valorAdicional + valorTotal30PorCento : valorAdicional;
            valorAdicional = devolucaoInput.ItensVistoria.CarroLimpo ? valorAdicional + valorTotal30PorCento : valorAdicional;
            valorAdicional = devolucaoInput.ItensVistoria.TanqueCheio ? valorAdicional + valorTotal30PorCento : valorAdicional;

            var outputModel = new DevolucaoOutputModel
            {
                Placa             = agendamento.Placa,
                CodigoReserva     = agendamento.CodigoReserva,
                ValorTotalReserva = agendamento.ValorTotalAluguel + valorAdicional,
                ItensReserva      = new DevolucaoOutputModel.Itens
                {
                    TotalHoras             = agendamento.TotalHoras,
                    ValorHora              = agendamento.ValorHoraVeiculo,
                    ValorAdicionalVistoria = valorAdicional
                }
            };

            return(Result <DevolucaoOutputModel> .Ok(outputModel));
        }