public CommodityPriceData(CommodityIdentity identity, ProductPriceDocument data)
        {
            if (null == identity)
            {
                throw new ArgumentNullException("Parameter 'identity' must not be null.", "identity");
            }

            if (null == data)
            {
                throw new ArgumentNullException("Parameter 'data' must not be null.", "data");
            }

            this.Identity = identity;
            this.Data     = data;
        }
Example #2
0
        public ProductPriceDocument[] GetProductPrices(string[] productIds, NorthwindConfig config)
        {
            List <ProductPriceDocument> items = new List <ProductPriceDocument>();
            DataSet          dataSet          = new DataSet();
            OleDbDataAdapter dataAdapter;

            string whereClause = "where";

            List <OleDbParameter> oleDbParameters = new List <OleDbParameter>();

            foreach (string productId in productIds)
            {
                whereClause += " ProductID=? OR";
                string         name       = "p" + oleDbParameters.Count.ToString();
                OleDbParameter oleDbParam = new OleDbParameter(name, Convert.ToInt32(productId));
                oleDbParameters.Add(oleDbParam);
            }

            whereClause = whereClause.Remove(whereClause.Length - 3, 3);

            string sqlQuery = "Select * from Products " + whereClause;

            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                dataAdapter = new OleDbDataAdapter(sqlQuery, connection);
                dataAdapter.SelectCommand.Parameters.AddRange(oleDbParameters.ToArray());
                if (dataAdapter.Fill(dataSet, "Products") == 0)
                {
                    // no products found
                }
                else
                {
                    foreach (DataRow row in dataSet.Tables["Products"].Rows)
                    {
                        ProductPriceDocument productPrice = new ProductPriceDocument();
                        productPrice.ProductId = Convert.ToInt32(row["ProductID"]);
                        productPrice.UnitPrice = Convert.ToDecimal(row["UnitPrice"]);

                        items.Add(productPrice);
                    }
                }
            }

            return(items.ToArray());
        }