public IActionResult Post([FromBody] CheckListDevolucaoModel checkListDevolucaoModelInsersao)
        {
            try
            {
                CheckListDevolucao checkListDevolucaoRequisicaoPost = _mapper.Map <CheckListDevolucaoModel, CheckListDevolucao>(checkListDevolucaoModelInsersao);

                if (checkListDevolucaoRequisicaoPost.Invalid)
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, new ErrorModel(checkListDevolucaoRequisicaoPost.Notifications)));
                }

                checkListDevolucaoRequisicaoPost = _devolucaoService.Devolver(checkListDevolucaoRequisicaoPost);

                if (checkListDevolucaoRequisicaoPost.Invalid)
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, new ErrorModel(checkListDevolucaoRequisicaoPost.Notifications)));
                }
                else
                {
                    return(Ok());
                }
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, Constantes.Mensagens.ServicoIndisponivel)); throw;
            }
        }
        public CheckListDevolucao Devolver(CheckListDevolucao devolucao)
        {
            Veiculo veiculoAluguel = _veiculoRepository.Obter(devolucao.IdVeiculo);

            if (veiculoAluguel == null)
            {
                devolucao.AddNotification(nameof(devolucao.IdVeiculo), $"Veículo [ID:{devolucao.IdVeiculo}] informado para devolução não existe.");
                return(devolucao);
            }

            Aluguel aluguel = _aluguelRepository.Obter(devolucao.IdAluguel);

            if (aluguel == null)
            {
                devolucao.AddNotification(nameof(devolucao.IdAluguel), $"Aluguel [ID:{devolucao.IdAluguel}] informado para devolução não existe.");
                return(devolucao);
            }

            if (devolucao.Valid)
            {
                devolucao.IdCheckListDevolucao = _checkListDevolucaoRepository.Inserir(devolucao);
                _veiculoRepository.AtualizarDisponibilidade(devolucao.IdVeiculo, false);
            }

            return(devolucao);
        }
        public IActionResult Put([FromBody] CheckListDevolucaoModel checkListDevolucaoAtualizacao)
        {
            try
            {
                CheckListDevolucao checkListDevolucaoRequisicaoPut = _mapper.Map <CheckListDevolucaoModel, CheckListDevolucao>(checkListDevolucaoAtualizacao);

                if (checkListDevolucaoRequisicaoPut.Invalid)
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, new ErrorModel(checkListDevolucaoRequisicaoPut.Notifications)));
                }

                var checkListDevolucaoExistente = _checkListDevolucaoRepositorio.Obter(checkListDevolucaoRequisicaoPut.IdCheckListDevolucao);

                if (checkListDevolucaoExistente != null)
                {
                    _checkListDevolucaoRepositorio.Atualizar(checkListDevolucaoRequisicaoPut);
                }
                else
                {
                    return(StatusCode(StatusCodes.Status404NotFound, Constantes.Mensagens.CheckListDevolucaoNaoEncontrado));
                }

                return(Ok());
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, Constantes.Mensagens.ServicoIndisponivel)); throw;
            }
        }
Beispiel #4
0
        public void CriarCheckListDevolucao_TotalAdicionalValido_Test()
        {
            var checkListDevolucao = new CheckListDevolucao(1, 1, new DateTime(2021, 1, 1), false, false, false, false, 200);

            Assert.True(checkListDevolucao.Valid);
            Assert.Equal(120, checkListDevolucao.TotalCobrancaAdicional);
        }
Beispiel #5
0
 public void Atualizar(CheckListDevolucao checkListDevolucao)
 {
     if (checkListDevolucao != null)
     {
         _checkListDevolucaoMock.RemoveAll(item => item.IdCheckListDevolucao == checkListDevolucao.IdCheckListDevolucao);
         _checkListDevolucaoMock.Add(checkListDevolucao);
     }
 }
Beispiel #6
0
        public void CriarCheckListDevolucao_CheckListDevolucaoInvalido_Test()
        {
            var checkListDevolucao = new CheckListDevolucao(0, 0, DateTime.MinValue, false, false, false, false, 0);

            Assert.True(checkListDevolucao.Invalid);
            Assert.Contains(checkListDevolucao.Notifications, n => n.Property == nameof(checkListDevolucao.IdAluguel));
            Assert.Contains(checkListDevolucao.Notifications, n => n.Property == nameof(checkListDevolucao.IdVeiculo));
            Assert.Contains(checkListDevolucao.Notifications, n => n.Property == nameof(checkListDevolucao.ValorAluguel));
        }
Beispiel #7
0
        public int Inserir(CheckListDevolucao checkListDevolucao)
        {
            int proximoId = 0;

            if (checkListDevolucao != null)
            {
                proximoId = _checkListDevolucaoMock.Max(al => al.IdAluguel);
                proximoId++;

                checkListDevolucao.IdAluguel = proximoId;
                _checkListDevolucaoMock.Add(checkListDevolucao);
            }
            return(proximoId);
        }
        public IActionResult ObterPorAluguel(int idAluguel)
        {
            try
            {
                CheckListDevolucao checkListDevolucao = _checkListDevolucaoRepositorio.ObterPorAluguel(idAluguel);

                if (checkListDevolucao == null)
                {
                    return(NotFound(Constantes.Mensagens.CheckListDevolucaoNaoEncontrado));
                }

                return(Ok(_mapper.Map <CheckListDevolucao, CheckListDevolucaoModel>(checkListDevolucao)));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, Constantes.Mensagens.ServicoIndisponivel));
            }
        }
Beispiel #9
0
        public void CriarCheckListDevolucao_CheckListDevolucaoValido_Test()
        {
            var checkListDevolucao = new CheckListDevolucao(1, 1, DateTime.Now, false, false, false, false, 200);

            Assert.True(checkListDevolucao.Valid);
        }