Exemple #1
0
        public bool UpdateProductFromDatabase(Product product)
        {
            string[] columns = new string[] {
                $"Name = '{product.Name}'",
                $"Price = {product.Price}"
            };
            string query = $"UPDATE Product SET {String.Join(",", columns)}, Image = @imagebinary WHERE Id = {product.Id}";

            SqlQueryParam param     = new SqlQueryParam("@imagebinary", SqlDbType.VarBinary, product.Image);
            var           paramList = new List <SqlQueryParam>()
            {
                param
            };

            return(ExecuteQuery(query, paramList));
        }
Exemple #2
0
        public bool AddProductToDatabase(ProductModel productModel)
        {
            string[] columns = new string[] {
                "Name",
                "Price",
                "Image"
            };
            string query = $"INSERT INTO Product ({String.Join(",", columns)}) VALUES('{productModel.Name}',{productModel.Price}, @imagebinary)";

            SqlQueryParam param     = new SqlQueryParam("@imagebinary", SqlDbType.VarBinary, productModel.Image);
            var           paramList = new List <SqlQueryParam>()
            {
                param
            };

            return(ExecuteQuery(query, paramList));
        }