/// <summary>
        /// The add.
        /// </summary>
        /// <param name="product">
        /// The product.
        /// </param>
        /// <param name="productAttributeValueSets">
        /// The product attribute value sets.
        /// </param>
        /// <param name="pictureIDs">
        /// The picture i ds.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int Add(Product product, List<Product_AttributeValueSet> productAttributeValueSets, List<string> pictureIDs, string masterPictureID)
        {
            var productID = 0;
            try
            {
                productID = this.productDA.Insert(product);
                //if (productAttributeValueSets != null && productAttributeValueSets.Count > 0)
                //{
                //    foreach (var productAttributeValueSet in productAttributeValueSets)
                //    {
                //        productAttributeValueSet.ProductID = productID;
                //        this.productAttributeValueSetDA.Insert(productAttributeValueSet, transaction);
                //    }
                //}

                foreach (var pictureID in pictureIDs)
                {
                    var productPicture = new Product_Picture
                                             {
                                                 ProductID = productID,
                                                 PictureID = Convert.ToInt32(pictureID),
                                                 IsMaster = pictureID == masterPictureID ? true : false
                                             };

                    this.productPictureDA.Insert(productPicture);
                }
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }

            return productID;
        }
Beispiel #2
0
        /// <summary>
        /// The update.
        /// </summary>
        /// <param name="product">
        /// The product.
        /// </param>
        /// <param name="transaction">
        /// The transaction.
        /// </param>
        public void Update(Product product, out SqlTransaction transaction)
        {
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }

            this.SqlServer.BeginTransaction(IsolationLevel.ReadCommitted);
            transaction = this.SqlServer.Transaction;
            var parameters = new List<SqlParameter>
                                 {
                                     this.SqlServer.CreateSqlParameter(
                                         "ID",
                                         SqlDbType.Int,
                                         product.ID,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Barcode",
                                         SqlDbType.NVarChar,
                                         product.Barcode,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Name",
                                         SqlDbType.NVarChar,
                                         product.Name,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "SEOTitle",
                                         SqlDbType.NVarChar,
                                         Utils.ToString(product.SEOTitle),
                                         ParameterDirection.Input),
                                     this.sqlServer.CreateSqlParameter(
                                         "SEOKeywords",
                                         SqlDbType.NVarChar,
                                         Utils.ToString(product.SEOKeywords),
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "SEODescription",
                                         SqlDbType.NVarChar,
                                         Utils.ToString(product.SEODescription),
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Advertisement",
                                         SqlDbType.NVarChar,
                                         Utils.ToString(product.Advertisement),
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "MarketPrice",
                                         SqlDbType.Float,
                                         product.MarketPrice,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "GoujiuPrice",
                                         SqlDbType.Float,
                                         product.GoujiuPrice,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Introduce",
                                         SqlDbType.NVarChar,
                                         product.Introduce,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Integral",
                                         SqlDbType.Int,
                                         product.Integral,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "SoldOfVirtual",
                                         SqlDbType.Int,
                                         Utils.ToString(product.SoldOfVirtual, "0"),
                                         ParameterDirection.Input),
                                     this.sqlServer.CreateSqlParameter(
                                         "InventoryNumber",
                                         SqlDbType.Int,
                                         product.InventoryNumber,
                                         ParameterDirection.Input),
                                     this.sqlServer.CreateSqlParameter(
                                         "Status",
                                         SqlDbType.Int,
                                         product.Status,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Attributes",
                                         SqlDbType.VarChar,
                                         product.Attributes,
                                         ParameterDirection.Input)
                                 };

            this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_Product_Update", parameters, null);
        }
        public Product SelectProductById(int id)
        {
            var parameters = new List<SqlParameter>()
                                 {
                                     this._sqlServer.CreateSqlParameter(
                                         "ProductID",
                                         SqlDbType.Int,
                                         id,
                                         ParameterDirection.Input)
                                 };
            var dataReader = this.SqlServer.ExecuteDataReader(CommandType.StoredProcedure, "sp_Picture_SelectByProductID", parameters, null);
            var list = dataReader.ToList<Product>();
            var product = new Product();
            if (list != null)
            {
                product = list.FirstOrDefault();
            }

            return product;
        }
Beispiel #4
0
        /// <summary>
        /// The insert.
        /// </summary>
        /// <param name="product">
        /// The product.
        /// </param>
        /// <param name="transaction">
        /// The transaction.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int Insert(Product product, out SqlTransaction transaction)
        {
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }

            this.SqlServer.BeginTransaction(IsolationLevel.ReadCommitted);
            transaction = this.SqlServer.Transaction;
            var parameters = new List<SqlParameter>
                                 {
                                     this.SqlServer.CreateSqlParameter(
                                         "ParentCategoryID",
                                         SqlDbType.Int,
                                         product.ParentCategoryID,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "ProductCategoryID",
                                         SqlDbType.Int,
                                         product.ProductCategoryID,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "ParentBrandID",
                                         SqlDbType.Int,
                                         product.ParentBrandID,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "ProductBrandID",
                                         SqlDbType.Int,
                                         product.ProductBrandID,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Barcode",
                                         SqlDbType.NVarChar,
                                         product.Barcode,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Name",
                                         SqlDbType.NVarChar,
                                         product.Name,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "SEOTitle",
                                         SqlDbType.NVarChar,
                                         product.SEOTitle,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "SEOKeywords",
                                         SqlDbType.NVarChar,
                                         product.SEOKeywords,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "SEODescription",
                                         SqlDbType.NVarChar,
                                         product.SEODescription,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Advertisement",
                                         SqlDbType.NVarChar,
                                         product.Advertisement,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "MarketPrice",
                                         SqlDbType.Float,
                                         product.MarketPrice,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "GoujiuPrice",
                                         SqlDbType.Float,
                                         product.GoujiuPrice,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Introduce",
                                         SqlDbType.NText,
                                         product.Introduce,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Integral",
                                         SqlDbType.Int,
                                         product.Integral,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "InventoryNumber",
                                         SqlDbType.Int,
                                         product.InventoryNumber,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "CommentNumber",
                                         SqlDbType.Int,
                                         0,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "SoldOfReality",
                                         SqlDbType.Int,
                                         0,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "SoldOfVirtual",
                                         SqlDbType.Int,
                                         product.SoldOfVirtual,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "PageView",
                                         SqlDbType.Int,
                                         product.PageView,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Sorting",
                                         SqlDbType.Int,
                                         0,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Status",
                                         SqlDbType.Int,
                                         product.Status,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "CreateTime",
                                         SqlDbType.DateTime,
                                         product.CreateTime,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Attributes",
                                         SqlDbType.VarChar,
                                         product.Attributes,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "ReferenceID",
                                         SqlDbType.Int,
                                         null,
                                         ParameterDirection.Output)
                                 };

            this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_Product_Insert", parameters, null);
            return (int)parameters.Find(parameter => parameter.ParameterName == "ReferenceID").Value;
        }