Example #1
0
def get_all_Products():

    c = Products(connection_data)

    result = c.get_all_Products()

    return jsonify({'data': result})
Example #2
0
def get_one_product(id):
    products = ProductsEntity(ProductID=id)

    c = Products(connection_data)

    result = c.get_one_Products(products)

    return jsonify({'data': result})
Example #3
0
File: app.py Project: tunghqh/KTWEB
def add_products():
    data = request.json
    products = ProductsEntity(product_name =data['product_name'],
                                supplier_id=data['supplier_id'],
                                category_id=data['category_id'],
                                unit=data['unit'],                             
                                price=data['price'])
    c = Products(connection_data)
    message = c.insert(products)
    if message is None:
        return jsonify({
            'message': 'Cannot insert data'
        }), 500
    return jsonify({
        'message': message
    })
Example #4
0
def add_Products():

    data = request.json

    pro = ProductsEntity(ProductName=data['ProductName'],
                         SupplierID=data['SupplierID'],
                         CategoryID=data['CategoryID'],
                         Unit=data['Unit'],
                         Price=data['Price'])

    c = Products(connection_data)

    message = c.insert_Products(pro)

    if message is None:

        return jsonify({'message': 'Cannot insert data'}), 500

    return jsonify({'message': message})
Example #5
0
def delete_Products_by_id(id):

    if request.method == 'DELETE':

        # Delete user by id

        product = ProductsEntity(ProductID=id)

        c = Products(connection_data)

        result = c.delete_Products(product)

        return jsonify({'message': result[0]}), result[1]

    else:
        # Update user by id

        data = request.json

        product = ProductsEntity(ProductID=id,
                                 ProductName=data['ProductName'],
                                 SupplierID=data['SupplierID'],
                                 CategoryID=data['CategoryID'],
                                 Unit=data['Unit'],
                                 Price=data['Price'])

        c = Products(connection_data)

        result = c.update_Products(product)

        return jsonify({'message': result[0]}), result[1]
Example #6
0
File: app.py Project: tunghqh/KTWEB
def delete_products_by_id(id):
    if request.method == 'DELETE':
        # Delete user by id
        products = ProductsEntity(product_id=id)
        c = Products(connection_data)
        result = c.delete(products)
        return jsonify({
            'message': result[0]
        }), result[1]
    else:
        data = request.json
        products = ProductsEntity(product_id=id,
                                    product_name =data['product_name'],
                                    supplier_id=data['supplier_id'],
                                    category_id=data['category_id'],
                                    unit=data['unit'],                             
                                    price=data['price'])
        c = Products(connection_data)
        result = c.update(products)
        return jsonify({
            'message': result[0]
        }), result[1]