Пример #1
0
        public IHttpActionResult PostPontoModel(long id, PontoModel ponto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            EstacionamentoModel est = db.EstacionamentoModels.Find(id);

            if (est == null)
            {
                return(BadRequest("Estacionamento não encontrado."));
            }
            est.Pontos.Add(ponto);

            db.Entry(est).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EstacionamentoModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(new { Id = ponto.Id }));
        }
Пример #2
0
        public IHttpActionResult PutEstacionamentoModel(long id, EstacionamentoModel estacionamentoModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != estacionamentoModel.Id)
            {
                return(BadRequest());
            }

            db.Entry(estacionamentoModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EstacionamentoModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        /// <summary>
        /// Inserir Veículo no Estacionamento
        /// </summary>
        public void EntrarVeiculo([FromBody] EstacionamentoModel obj)
        {
            if (!conexao.IsOpen)
            {
                conexao.Open();
            }

            DB2Transaction trans = conexao.BeginTransaction();

            try
            {
                new EstacionamentoDao(conexao, trans).EntrarVeiculo(obj);
                trans.Commit();
            }
            catch (Exception ex)
            {
                trans.Rollback();
                throw new Exception(ex.Message);
            }
            finally
            {
                if (conexao.IsOpen)
                {
                    conexao.Close();
                }
            }
        }
        public void EntrarVeiculo(EstacionamentoModel controle)
        {
            string sql = @"INSERT INTO KARSTEN.TST001_CONTROLE_ENTRADA_VEICULO 
                           (MODELO_VEICULO, PLACA_VEICULO, DATA_ENTRADA, OBSERVACAO_VEICULO)
                          VALUES (@Modelo_veiculo, @Placa_veiculo, CURRENT TIMESTAMP, @Observacao_veiculo)";

            conexao.ExecuteScalar(sql, param: controle, transaction: transacao);
        }
Пример #5
0
        public IHttpActionResult GetEstacionamentoModel(long id)
        {
            EstacionamentoModel estacionamentoModel = db.EstacionamentoModels.Find(id);

            if (estacionamentoModel == null)
            {
                return(NotFound());
            }

            return(Ok(estacionamentoModel));
        }
Пример #6
0
        public IHttpActionResult PostEstacionamentoModel(EstacionamentoModel estacionamentoModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            estacionamentoModel.Responsavel = db.UsuarioModels.Find(estacionamentoModel.Responsavel.Id);
            db.EstacionamentoModels.Add(estacionamentoModel);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = estacionamentoModel.Id }, estacionamentoModel));
        }
Пример #7
0
        public IHttpActionResult DeleteEstacionamentoModel(long id)
        {
            EstacionamentoModel estacionamentoModel = db.EstacionamentoModels.Find(id);

            if (estacionamentoModel == null)
            {
                return(NotFound());
            }



            db.EstacionamentoModels.Remove(estacionamentoModel);
            db.SaveChanges();

            return(Ok(estacionamentoModel));
        }
Пример #8
0
        public async Task Test_Estaciona()
        {
            var estacionar = new EstacionamentoModel
            {
                Id               = 0,
                Estado           = "A",
                IdVaga           = 108,
                DataHora_Entrada = DateTime.Now,
                DataHora_Saida   = DateTime.MinValue,
                IdVeiculo        = 2
            };

            var content       = JsonConvert.SerializeObject(estacionar);
            var stringContent = new StringContent(content, Encoding.UTF8, "application/json");


            // Act
            var result = new EstacionamentoController(contexto).Novo(estacionar);

            // Assert
            var okResult = result.Should().BeOfType <OkObjectResult>().Subject;
        }
Пример #9
0
        public IActionResult Novo([FromBody] EstacionamentoModel dados)
        {
            ResultMessageServices retorno = new ResultMessageServices();

            try
            {
                AutenticacaoAPI.Autenticar();
                dados.RegistrarVagaEstacionamento();
                retorno.Result      = true;
                retorno.ErroMessage = string.Empty;
            }
            catch (UnauthorizedAccessException erroautorizacao)
            {
                return(StatusCode((int)HttpStatusCode.Unauthorized, erroautorizacao.Message));
            }
            catch (Exception erro)
            {
                retorno.Result      = false;
                retorno.ErroMessage = "Erro ao tentar registrar vaga. " + erro.Message.ToString();
            }
            return(new OkObjectResult(retorno));
        }