Beispiel #1
0
        public IActionResult CalculaHora(int id, DateTime dataSaida)
        {
            var result = _movimentacaoService.CalculaPermanencia(id, dataSaida);
            //Json.Serialize()
            SaidaVeiculoViewModel vm = _factory.PrepareSaidaVeiculoViewModel(result);

            return(Ok(JsonConvert.SerializeObject(vm)));
        }
Beispiel #2
0
 private void SetSaidaVeiculoViewModel(Movimentacao mov, ref SaidaVeiculoViewModel viewModel)
 {
     viewModel.Id          = mov.Id;
     viewModel.Entrada     = mov.Entrada;
     viewModel.Saida       = mov.Saida ?? DateTime.Now;
     viewModel.Veiculo     = $"{mov.Veiculo.Placa}- {mov.Veiculo.Descricao}";
     viewModel.Permanencia = (viewModel.Saida - viewModel.Entrada).ToString("hh\\:mm");
     viewModel.Quantidade  = mov.Quantidade ?? 0;
     viewModel.ValorHora   = mov.Valor ?? 0;
     viewModel.Total       = mov.ValorTotal ?? 0;
     viewModel.Mensagem    = string.Empty;
 }
Beispiel #3
0
        public SaidaVeiculoViewModel PrepareSaidaVeiculoViewModel(Movimentacao movimentacao)
        {
            SaidaVeiculoViewModel viewModel = new SaidaVeiculoViewModel();

            if (!movimentacao.Saida.HasValue)
            {
                viewModel.Saida    = DateTime.Now;
                movimentacao.Saida = viewModel.Saida;
                _movimentacaoService.CalculaPermanencia(movimentacao);
            }
            SetSaidaVeiculoViewModel(movimentacao, ref viewModel);
            return(viewModel);
        }
Beispiel #4
0
 public async Task <IActionResult> ConfirmarSaida(SaidaVeiculoViewModel viewModel)
 {
     try
     {
         await _factory.SaveSaidaAsync(viewModel.Id, viewModel.Saida);
     }
     catch (ModelValidateException ex)
     {
         ex.Results.AddToModelState(ModelState, null);
         return(View("Saida", viewModel));
     }
     catch (Exception ex)
     {
         viewModel.Mensagem = $"Ocorreu um erro inesperado! Descricão: {ex.Message}";
         return(View("Saida", viewModel));
     }
     return(RedirectToAction("Index"));
 }