Exemplo n.º 1
0
        public int Modificacion(Alquiler p)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"UPDATE Alquiler SET Precio='{p.Precio}', FechaInicio='{p.FechaInicio}', FechaFin='{p.FechaFin}', InquilinoId='{p.InquilinoId}', InmuebleId='{p.InmuebleId}'" +
                             $"WHERE IdAlquiler = {p.IdAlquiler}";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    res = command.ExecuteNonQuery();
                    connection.Close();
                }
            }
            return(res);
        }
Exemplo n.º 2
0
        public int Alta(Alquiler p)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"INSERT INTO Alquiler (Precio,FechaInicio, FechaFin, InquilinoId, InmuebleId) " +
                             $"VALUES ('{p.Precio}','{p.FechaInicio}', '{p.FechaFin}','{p.InquilinoId}','{p.InmuebleId}')";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    res = command.ExecuteNonQuery();
                    command.CommandText = "SELECT SCOPE_IDENTITY()";
                    var id = command.ExecuteScalar();
                    p.IdAlquiler = Convert.ToInt32(id);
                    connection.Close();
                }
            }
            return(res);
        }