Beispiel #1
0
        public static ProductActionStatus UpdateProduct(ProductInfo product, Dictionary <string, SKUItem> skus, Dictionary <int, IList <int> > attrs, IList <int> distributorUserIds)
        {
            if (null == product)
            {
                return(ProductActionStatus.UnknowError);
            }
            Globals.EntityCoding(product, true);
            int decimalLength = HiContext.Current.SiteSettings.DecimalLength;

            if (product.MarketPrice.HasValue)
            {
                product.MarketPrice = new decimal?(Math.Round(product.MarketPrice.Value, decimalLength));
            }
            product.LowestSalePrice = Math.Round(product.LowestSalePrice, decimalLength);
            ProductActionStatus unknowError = ProductActionStatus.UnknowError;

            using (DbConnection connection = DatabaseFactory.CreateDatabase().CreateConnection())
            {
                connection.Open();
                DbTransaction dbTran = connection.BeginTransaction();
                try
                {
                    ProductProvider provider = ProductProvider.Instance();
                    if (!provider.UpdateProduct(product, dbTran))
                    {
                        dbTran.Rollback();
                        return(ProductActionStatus.DuplicateSKU);
                    }
                    if (!provider.DeleteProductSKUS(product.ProductId, dbTran))
                    {
                        dbTran.Rollback();
                        return(ProductActionStatus.SKUError);
                    }
                    if (((skus != null) && (skus.Count > 0)) && !provider.AddProductSKUs(product.ProductId, skus, dbTran))
                    {
                        dbTran.Rollback();
                        return(ProductActionStatus.SKUError);
                    }
                    if (!provider.AddProductAttributes(product.ProductId, attrs, dbTran))
                    {
                        dbTran.Rollback();
                        return(ProductActionStatus.AttributeError);
                    }
                    if (!provider.OffShelfProductExcludedSalePrice(product.ProductId, product.LowestSalePrice, dbTran))
                    {
                        dbTran.Rollback();
                        return(ProductActionStatus.OffShelfError);
                    }
                    dbTran.Commit();
                    unknowError = ProductActionStatus.Success;
                }
                catch (Exception)
                {
                    dbTran.Rollback();
                }
                finally
                {
                    connection.Close();
                }
            }
            if (unknowError == ProductActionStatus.Success)
            {
                ProductProvider.Instance().DeleteSkuUnderlingPrice();
                if (product.PenetrationStatus == PenetrationStatus.Notyet)
                {
                    List <int> productIds = new List <int>();
                    productIds.Add(product.ProductId);
                    DeleteCanclePenetrationProducts(productIds, null);
                }
                if ((distributorUserIds != null) && (distributorUserIds.Count != 0))
                {
                    foreach (int num2 in distributorUserIds)
                    {
                        DeleteNotinProductLines(num2);
                    }
                }
                EventLogs.WriteOperationLog(Privilege.EditProducts, string.Format(CultureInfo.InvariantCulture, "修改了编号为 “{0}” 的商品", new object[] { product.ProductId }));
            }
            return(unknowError);
        }