Beispiel #1
0
        public async Task <Veiculo> AlteraVeiculoAsync(locadora.models.Veiculo veiculonovo)
        {
            var cmd = Db.Connection.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"UPDATE veiculos SET " +
                              "marca = @marca, " +
                              "ano = @ano, " +
                              "descricao = @descricao, " +
                              "vendido = @vendido, " +
                              "updated = @updated " +
                              "WHERE " +
                              "placa = @placa ";
            cmd.Parameters.Add(new MySqlParameter
            {
                ParameterName = "@placa",
                DbType        = DbType.String,
                Value         = veiculonovo.Placa,
            });
            cmd.Parameters.Add(new MySqlParameter
            {
                ParameterName = "@marca",
                DbType        = DbType.String,
                Value         = veiculonovo.Marca,
            });
            cmd.Parameters.Add(new MySqlParameter
            {
                ParameterName = "@ano",
                DbType        = DbType.Int32,
                Value         = veiculonovo.Ano,
            });
            cmd.Parameters.Add(new MySqlParameter
            {
                ParameterName = "@descricao",
                DbType        = DbType.String,
                Value         = veiculonovo.Descricao,
            });
            cmd.Parameters.Add(new MySqlParameter
            {
                ParameterName = "@vendido",
                DbType        = DbType.Boolean,
                Value         = veiculonovo.Vendido,
            });
            cmd.Parameters.Add(new MySqlParameter
            {
                ParameterName = "@updated",
                DbType        = DbType.DateTime,
                Value         = DateTime.Today,
            });

            var result = await ReadAllAsync(await cmd.ExecuteReaderAsync());

            return(result.Count > 0 ? result[0] : null);
        }
Beispiel #2
0
        public async Task <Veiculo> InsereNovoVeiculoAsync(locadora.models.Veiculo veiculonovo)
        {
            var cmd = Db.Connection.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO veiculos " +
                              "(placa, " +
                              "marca, " +
                              "ano, " +
                              "descricao, " +
                              "vendido, " +
                              "created, " +
                              "updated) " +
                              "VALUES " +
                              "(@placa, " +
                              "@marca, " +
                              "@ano, " +
                              "@descricao, " +
                              "@vendido, " +
                              "@created, " +
                              "@updated)";
            cmd.Parameters.Add(new MySqlParameter
            {
                ParameterName = "@placa",
                DbType        = DbType.String,
                Value         = veiculonovo.Placa,
            });
            cmd.Parameters.Add(new MySqlParameter
            {
                ParameterName = "@marca",
                DbType        = DbType.String,
                Value         = veiculonovo.Marca,
            });
            cmd.Parameters.Add(new MySqlParameter
            {
                ParameterName = "@ano",
                DbType        = DbType.Int32,
                Value         = veiculonovo.Ano,
            });
            cmd.Parameters.Add(new MySqlParameter
            {
                ParameterName = "@descricao",
                DbType        = DbType.String,
                Value         = veiculonovo.Descricao,
            });
            cmd.Parameters.Add(new MySqlParameter
            {
                ParameterName = "@vendido",
                DbType        = DbType.Boolean,
                Value         = veiculonovo.Vendido,
            });
            cmd.Parameters.Add(new MySqlParameter
            {
                ParameterName = "@created",
                DbType        = DbType.DateTime,
                Value         = DateTime.Today,
            });
            cmd.Parameters.Add(new MySqlParameter
            {
                ParameterName = "@updated",
                DbType        = DbType.DateTime,
                Value         = DateTime.Today,
            });

            var result = await ReadAllAsync(await cmd.ExecuteReaderAsync());

            return(result.Count > 0 ? result[0] : null);
        }