示例#1
0
        public Product SaveInfo()
        {
            DateTime nowDT = DateTime.UtcNow;

            string name                 = txtName.Text.Trim();
            string shortDescription     = txtShortDescription.Text.Trim();
            string fullDescription      = txtFullDescription.Value.Trim();
            string adminComment         = txtAdminComment.Text.Trim();
            int    templateId           = int.Parse(this.ddlTemplate.SelectedItem.Value);
            bool   showOnHomePage       = cbShowOnHomePage.Checked;
            bool   allowCustomerReviews = cbAllowCustomerReviews.Checked;
            bool   allowCustomerRatings = cbAllowCustomerRatings.Checked;
            bool   published            = cbPublished.Checked;
            string sku = txtSKU.Text.Trim();
            string manufacturerPartNumber   = txtManufacturerPartNumber.Text.Trim();
            bool   isGiftCard               = cbIsGiftCard.Checked;
            int    giftCardType             = int.Parse(this.ddlGiftCardType.SelectedItem.Value);
            bool   isDownload               = cbIsDownload.Checked;
            int    productVariantDownloadId = 0;

            if (isDownload)
            {
                bool   useDownloadURL = cbUseDownloadURL.Checked;
                string downloadURL    = txtDownloadURL.Text.Trim();
                byte[] productVariantDownloadBinary = null;
                string downloadContentType          = string.Empty;
                string downloadFilename             = string.Empty;
                string downloadExtension            = string.Empty;

                HttpPostedFile productVariantDownloadFile = fuProductVariantDownload.PostedFile;
                if ((productVariantDownloadFile != null) && (!String.IsNullOrEmpty(productVariantDownloadFile.FileName)))
                {
                    productVariantDownloadBinary = productVariantDownloadFile.GetDownloadBits();
                    downloadContentType          = productVariantDownloadFile.ContentType;
                    downloadFilename             = Path.GetFileNameWithoutExtension(productVariantDownloadFile.FileName);
                    downloadExtension            = Path.GetExtension(productVariantDownloadFile.FileName);
                }

                var productVariantDownload = new Download()
                {
                    UseDownloadUrl = useDownloadURL,
                    DownloadUrl    = downloadURL,
                    DownloadBinary = productVariantDownloadBinary,
                    ContentType    = downloadContentType,
                    Filename       = downloadFilename,
                    Extension      = downloadExtension,
                    IsNew          = true
                };
                this.DownloadService.InsertDownload(productVariantDownload);
                productVariantDownloadId = productVariantDownload.DownloadId;
            }

            bool unlimitedDownloads     = cbUnlimitedDownloads.Checked;
            int  maxNumberOfDownloads   = txtMaxNumberOfDownloads.Value;
            int? downloadExpirationDays = null;

            if (!String.IsNullOrEmpty(txtDownloadExpirationDays.Text.Trim()))
            {
                downloadExpirationDays = int.Parse(txtDownloadExpirationDays.Text.Trim());
            }
            DownloadActivationTypeEnum downloadActivationType = (DownloadActivationTypeEnum)Enum.ToObject(typeof(DownloadActivationTypeEnum), int.Parse(this.ddlDownloadActivationType.SelectedItem.Value));
            bool   hasUserAgreement  = cbHasUserAgreement.Checked;
            string userAgreementText = txtUserAgreementText.Value;

            bool hasSampleDownload = cbHasSampleDownload.Checked;
            int  productVariantSampleDownloadId = 0;

            if (hasSampleDownload)
            {
                bool   useSampleDownloadURL = cbUseSampleDownloadURL.Checked;
                string sampleDownloadURL    = txtSampleDownloadURL.Text.Trim();
                byte[] productVariantSampleDownloadBinary = null;
                string sampleDownloadContentType          = string.Empty;
                string sampleDownloadFilename             = string.Empty;
                string sampleDownloadExtension            = string.Empty;

                HttpPostedFile productVariantSampleDownloadFile = fuProductVariantSampleDownload.PostedFile;
                if ((productVariantSampleDownloadFile != null) && (!String.IsNullOrEmpty(productVariantSampleDownloadFile.FileName)))
                {
                    productVariantSampleDownloadBinary = productVariantSampleDownloadFile.GetDownloadBits();
                    sampleDownloadContentType          = productVariantSampleDownloadFile.ContentType;
                    sampleDownloadFilename             = Path.GetFileNameWithoutExtension(productVariantSampleDownloadFile.FileName);
                    sampleDownloadExtension            = Path.GetExtension(productVariantSampleDownloadFile.FileName);
                }

                var productVariantSampleDownload = new Download()
                {
                    UseDownloadUrl = useSampleDownloadURL,
                    DownloadUrl    = sampleDownloadURL,
                    DownloadBinary = productVariantSampleDownloadBinary,
                    ContentType    = sampleDownloadContentType,
                    Filename       = sampleDownloadFilename,
                    Extension      = sampleDownloadExtension,
                    IsNew          = true
                };
                this.DownloadService.InsertDownload(productVariantSampleDownload);
                productVariantSampleDownloadId = productVariantSampleDownload.DownloadId;
            }

            bool isRecurring = cbIsRecurring.Checked;
            int  cycleLength = txtCycleLength.Value;
            RecurringProductCyclePeriodEnum cyclePeriod = (RecurringProductCyclePeriodEnum)Enum.ToObject(typeof(RecurringProductCyclePeriodEnum), int.Parse(this.ddlCyclePeriod.SelectedItem.Value));
            int totalCycles = txtTotalCycles.Value;

            bool    isShipEnabled            = cbIsShipEnabled.Checked;
            bool    isFreeShipping           = cbIsFreeShipping.Checked;
            decimal additionalShippingCharge = txtAdditionalShippingCharge.Value;
            bool    isTaxExempt                   = cbIsTaxExempt.Checked;
            int     taxCategoryId                 = int.Parse(this.ddlTaxCategory.SelectedItem.Value);
            int     manageStock                   = Convert.ToInt32(ddlManageStock.SelectedValue);
            int     stockQuantity                 = txtStockQuantity.Value;
            bool    displayStockAvailability      = cbDisplayStockAvailability.Checked;
            bool    displayStockQuantity          = cbDisplayStockQuantity.Checked;
            int     minStockQuantity              = txtMinStockQuantity.Value;
            LowStockActivityEnum lowStockActivity = (LowStockActivityEnum)Enum.ToObject(typeof(LowStockActivityEnum), int.Parse(this.ddlLowStockActivity.SelectedItem.Value));
            int      notifyForQuantityBelow       = txtNotifyForQuantityBelow.Value;
            int      backorders                   = int.Parse(this.ddlBackorders.SelectedItem.Value);
            int      orderMinimumQuantity         = txtOrderMinimumQuantity.Value;
            int      orderMaximumQuantity         = txtOrderMaximumQuantity.Value;
            int      warehouseId                  = int.Parse(this.ddlWarehouse.SelectedItem.Value);
            bool     disableBuyButton             = cbDisableBuyButton.Checked;
            bool     callForPrice                 = cbCallForPrice.Checked;
            decimal  price                       = txtPrice.Value;
            decimal  oldPrice                    = txtOldPrice.Value;
            decimal  productCost                 = txtProductCost.Value;
            bool     customerEntersPrice         = cbCustomerEntersPrice.Checked;
            decimal  minimumCustomerEnteredPrice = txtMinimumCustomerEnteredPrice.Value;
            decimal  maximumCustomerEnteredPrice = txtMaximumCustomerEnteredPrice.Value;
            decimal  weight                      = txtWeight.Value;
            decimal  length                      = txtLength.Value;
            decimal  width                       = txtWidth.Value;
            decimal  height                      = txtHeight.Value;
            DateTime?availableStartDateTime      = ctrlAvailableStartDateTimePicker.SelectedDate;
            DateTime?availableEndDateTime        = ctrlAvailableEndDateTimePicker.SelectedDate;

            if (availableStartDateTime.HasValue)
            {
                availableStartDateTime = DateTime.SpecifyKind(availableStartDateTime.Value, DateTimeKind.Utc);
            }
            if (availableEndDateTime.HasValue)
            {
                availableEndDateTime = DateTime.SpecifyKind(availableEndDateTime.Value, DateTimeKind.Utc);
            }

            //product
            var product = new Product()
            {
                Name                 = name,
                ShortDescription     = shortDescription,
                FullDescription      = fullDescription,
                AdminComment         = adminComment,
                TemplateId           = templateId,
                ShowOnHomePage       = showOnHomePage,
                AllowCustomerReviews = allowCustomerReviews,
                AllowCustomerRatings = allowCustomerRatings,
                Published            = published,
                CreatedOn            = nowDT,
                UpdatedOn            = nowDT
            };

            this.ProductService.InsertProduct(product);


            //product variant
            var productVariant = new ProductVariant()
            {
                ProductId = product.ProductId,
                SKU       = sku,
                ManufacturerPartNumber      = manufacturerPartNumber,
                IsGiftCard                  = isGiftCard,
                GiftCardType                = giftCardType,
                IsDownload                  = isDownload,
                DownloadId                  = productVariantDownloadId,
                UnlimitedDownloads          = unlimitedDownloads,
                MaxNumberOfDownloads        = maxNumberOfDownloads,
                DownloadExpirationDays      = downloadExpirationDays,
                DownloadActivationType      = (int)downloadActivationType,
                HasSampleDownload           = hasSampleDownload,
                SampleDownloadId            = productVariantSampleDownloadId,
                HasUserAgreement            = hasUserAgreement,
                UserAgreementText           = userAgreementText,
                IsRecurring                 = isRecurring,
                CycleLength                 = cycleLength,
                CyclePeriod                 = (int)cyclePeriod,
                TotalCycles                 = totalCycles,
                IsShipEnabled               = isShipEnabled,
                IsFreeShipping              = isFreeShipping,
                AdditionalShippingCharge    = additionalShippingCharge,
                IsTaxExempt                 = isTaxExempt,
                TaxCategoryId               = taxCategoryId,
                ManageInventory             = manageStock,
                StockQuantity               = stockQuantity,
                DisplayStockAvailability    = displayStockAvailability,
                DisplayStockQuantity        = displayStockQuantity,
                MinStockQuantity            = minStockQuantity,
                LowStockActivityId          = (int)lowStockActivity,
                NotifyAdminForQuantityBelow = notifyForQuantityBelow,
                Backorders                  = backorders,
                OrderMinimumQuantity        = orderMinimumQuantity,
                OrderMaximumQuantity        = orderMaximumQuantity,
                WarehouseId                 = warehouseId,
                DisableBuyButton            = disableBuyButton,
                CallForPrice                = callForPrice,
                Price                       = price,
                OldPrice                    = oldPrice,
                ProductCost                 = productCost,
                CustomerEntersPrice         = customerEntersPrice,
                MinimumCustomerEnteredPrice = minimumCustomerEnteredPrice,
                MaximumCustomerEnteredPrice = maximumCustomerEnteredPrice,
                Weight                      = weight,
                Length                      = length,
                Width                       = width,
                Height                      = height,
                AvailableStartDateTime      = availableStartDateTime,
                AvailableEndDateTime        = availableEndDateTime,
                Published                   = published,
                Deleted                     = false,
                DisplayOrder                = 1,
                CreatedOn                   = nowDT,
                UpdatedOn                   = nowDT
            };

            this.ProductService.InsertProductVariant(productVariant);

            SaveLocalizableContent(product);

            //product tags
            string[] newProductTags = ParseProductTags(txtProductTags.Text);
            foreach (string productTagName in newProductTags)
            {
                ProductTag productTag  = null;
                var        productTag2 = this.ProductService.GetProductTagByName(productTagName);
                if (productTag2 == null)
                {
                    //add new product tag
                    productTag = new ProductTag()
                    {
                        Name         = productTagName,
                        ProductCount = 0
                    };
                    this.ProductService.InsertProductTag(productTag);
                }
                else
                {
                    productTag = productTag2;
                }
                this.ProductService.AddProductTagMapping(product.ProductId, productTag.ProductTagId);
            }

            return(product);
        }
示例#2
0
        public ProductVariant SaveInfo()
        {
            DateTime nowDT = DateTime.UtcNow;

            string name                   = txtName.Text.Trim();
            string sku                    = txtSKU.Text.Trim();
            string description            = txtDescription.Value;
            string adminComment           = txtAdminComment.Text.Trim();
            string manufacturerPartNumber = txtManufacturerPartNumber.Text.Trim();
            bool   isGiftCard             = cbIsGiftCard.Checked;
            int    giftCardType           = int.Parse(this.ddlGiftCardType.SelectedItem.Value);
            bool   isDownload             = cbIsDownload.Checked;
            bool   unlimitedDownloads     = cbUnlimitedDownloads.Checked;
            int    maxNumberOfDownloads   = txtMaxNumberOfDownloads.Value;
            int?   downloadExpirationDays = null;

            if (!String.IsNullOrEmpty(txtDownloadExpirationDays.Text.Trim()))
            {
                downloadExpirationDays = int.Parse(txtDownloadExpirationDays.Text.Trim());
            }
            DownloadActivationTypeEnum downloadActivationType = (DownloadActivationTypeEnum)Enum.ToObject(typeof(DownloadActivationTypeEnum), int.Parse(this.ddlDownloadActivationType.SelectedItem.Value));
            bool   hasUserAgreement  = cbHasUserAgreement.Checked;
            string userAgreementText = txtUserAgreementText.Value;
            bool   hasSampleDownload = cbHasSampleDownload.Checked;

            bool isRecurring = cbIsRecurring.Checked;
            int  cycleLength = txtCycleLength.Value;
            RecurringProductCyclePeriodEnum cyclePeriod = (RecurringProductCyclePeriodEnum)Enum.ToObject(typeof(RecurringProductCyclePeriodEnum), int.Parse(this.ddlCyclePeriod.SelectedItem.Value));
            int totalCycles = txtTotalCycles.Value;

            bool    isShipEnabled            = cbIsShipEnabled.Checked;
            bool    isFreeShipping           = cbIsFreeShipping.Checked;
            decimal additionalShippingCharge = txtAdditionalShippingCharge.Value;
            bool    isTaxExempt                   = cbIsTaxExempt.Checked;
            int     taxCategoryId                 = int.Parse(this.ddlTaxCategory.SelectedItem.Value);
            int     manageStock                   = Convert.ToInt32(ddlManageStock.SelectedValue);
            int     stockQuantity                 = txtStockQuantity.Value;
            bool    displayStockAvailability      = cbDisplayStockAvailability.Checked;
            bool    displayStockQuantity          = cbDisplayStockQuantity.Checked;
            int     minStockQuantity              = txtMinStockQuantity.Value;
            LowStockActivityEnum lowStockActivity = (LowStockActivityEnum)Enum.ToObject(typeof(LowStockActivityEnum), int.Parse(this.ddlLowStockActivity.SelectedItem.Value));
            int      notifyForQuantityBelow       = txtNotifyForQuantityBelow.Value;
            int      backorders                   = int.Parse(this.ddlBackorders.SelectedItem.Value);
            int      orderMinimumQuantity         = txtOrderMinimumQuantity.Value;
            int      orderMaximumQuantity         = txtOrderMaximumQuantity.Value;
            int      warehouseId                  = int.Parse(this.ddlWarehouse.SelectedItem.Value);
            bool     disableBuyButton             = cbDisableBuyButton.Checked;
            bool     callForPrice                 = cbCallForPrice.Checked;
            decimal  price                       = txtPrice.Value;
            decimal  oldPrice                    = txtOldPrice.Value;
            decimal  productCost                 = txtProductCost.Value;
            bool     customerEntersPrice         = cbCustomerEntersPrice.Checked;
            decimal  minimumCustomerEnteredPrice = txtMinimumCustomerEnteredPrice.Value;
            decimal  maximumCustomerEnteredPrice = txtMaximumCustomerEnteredPrice.Value;
            decimal  weight                      = txtWeight.Value;
            decimal  length                      = txtLength.Value;
            decimal  width                       = txtWidth.Value;
            decimal  height                      = txtHeight.Value;
            DateTime?availableStartDateTime      = ctrlAvailableStartDateTimePicker.SelectedDate;
            DateTime?availableEndDateTime        = ctrlAvailableEndDateTimePicker.SelectedDate;

            if (availableStartDateTime.HasValue)
            {
                availableStartDateTime = DateTime.SpecifyKind(availableStartDateTime.Value, DateTimeKind.Utc);
            }
            if (availableEndDateTime.HasValue)
            {
                availableEndDateTime = DateTime.SpecifyKind(availableEndDateTime.Value, DateTimeKind.Utc);
            }
            bool published    = cbPublished.Checked;
            int  displayOrder = txtDisplayOrder.Value;

            ProductVariant productVariant = this.ProductService.GetProductVariantById(ProductVariantId);

            if (productVariant != null)
            {
                #region Update
                Picture        productVariantPicture     = productVariant.Picture;
                HttpPostedFile productVariantPictureFile = fuProductVariantPicture.PostedFile;
                if ((productVariantPictureFile != null) && (!String.IsNullOrEmpty(productVariantPictureFile.FileName)))
                {
                    byte[] productVariantPictureBinary = productVariantPictureFile.GetPictureBits();
                    if (productVariantPicture != null)
                    {
                        productVariantPicture = this.PictureService.UpdatePicture(productVariantPicture.PictureId, productVariantPictureBinary, productVariantPictureFile.ContentType, true);
                    }
                    else
                    {
                        productVariantPicture = this.PictureService.InsertPicture(productVariantPictureBinary, productVariantPictureFile.ContentType, true);
                    }
                }
                int productVariantPictureId = 0;
                if (productVariantPicture != null)
                {
                    productVariantPictureId = productVariantPicture.PictureId;
                }

                int productVariantDownloadId = 0;
                if (isDownload)
                {
                    Download productVariantDownload       = productVariant.Download;
                    bool     useDownloadURL               = cbUseDownloadURL.Checked;
                    string   downloadURL                  = txtDownloadURL.Text.Trim();
                    byte[]   productVariantDownloadBinary = null;
                    string   downloadContentType          = string.Empty;
                    string   downloadFilename             = string.Empty;
                    string   downloadExtension            = string.Empty;
                    if (productVariantDownload != null)
                    {
                        productVariantDownloadBinary = productVariantDownload.DownloadBinary;
                        downloadContentType          = productVariantDownload.ContentType;
                        downloadFilename             = productVariantDownload.Filename;
                        downloadExtension            = productVariantDownload.Extension;
                    }

                    HttpPostedFile productVariantDownloadFile = fuProductVariantDownload.PostedFile;
                    if ((productVariantDownloadFile != null) && (!String.IsNullOrEmpty(productVariantDownloadFile.FileName)))
                    {
                        productVariantDownloadBinary = productVariantDownloadFile.GetDownloadBits();
                        downloadContentType          = productVariantDownloadFile.ContentType;
                        downloadFilename             = Path.GetFileNameWithoutExtension(productVariantDownloadFile.FileName);
                        downloadExtension            = Path.GetExtension(productVariantDownloadFile.FileName);
                    }

                    if (productVariantDownload != null)
                    {
                        productVariantDownload.UseDownloadUrl = useDownloadURL;
                        productVariantDownload.DownloadUrl    = downloadURL;
                        productVariantDownload.DownloadBinary = productVariantDownloadBinary;
                        productVariantDownload.ContentType    = downloadContentType;
                        productVariantDownload.Filename       = downloadFilename;
                        productVariantDownload.Extension      = downloadExtension;
                        productVariantDownload.IsNew          = true;
                        this.DownloadService.UpdateDownload(productVariantDownload);
                    }
                    else
                    {
                        productVariantDownload = new Download()
                        {
                            UseDownloadUrl = useDownloadURL,
                            DownloadUrl    = downloadURL,
                            DownloadBinary = productVariantDownloadBinary,
                            ContentType    = downloadContentType,
                            Filename       = downloadFilename,
                            Extension      = downloadExtension,
                            IsNew          = true
                        };
                        this.DownloadService.InsertDownload(productVariantDownload);
                    }

                    productVariantDownloadId = productVariantDownload.DownloadId;
                }

                int productVariantSampleDownloadId = 0;
                if (hasSampleDownload)
                {
                    Download productVariantSampleDownload       = productVariant.SampleDownload;
                    bool     useSampleDownloadURL               = cbUseSampleDownloadURL.Checked;
                    string   sampleDownloadURL                  = txtSampleDownloadURL.Text.Trim();
                    byte[]   productVariantSampleDownloadBinary = null;
                    string   sampleDownloadContentType          = string.Empty;
                    string   sampleDownloadFilename             = string.Empty;
                    string   sampleDownloadExtension            = string.Empty;
                    if (productVariantSampleDownload != null)
                    {
                        productVariantSampleDownloadBinary = productVariantSampleDownload.DownloadBinary;
                        sampleDownloadContentType          = productVariantSampleDownload.ContentType;
                        sampleDownloadFilename             = productVariantSampleDownload.Filename;
                        sampleDownloadExtension            = productVariantSampleDownload.Extension;
                    }

                    HttpPostedFile productVariantSampleDownloadFile = fuProductVariantSampleDownload.PostedFile;
                    if ((productVariantSampleDownloadFile != null) && (!String.IsNullOrEmpty(productVariantSampleDownloadFile.FileName)))
                    {
                        productVariantSampleDownloadBinary = productVariantSampleDownloadFile.GetDownloadBits();
                        sampleDownloadContentType          = productVariantSampleDownloadFile.ContentType;
                        sampleDownloadFilename             = Path.GetFileNameWithoutExtension(productVariantSampleDownloadFile.FileName);
                        sampleDownloadExtension            = Path.GetExtension(productVariantSampleDownloadFile.FileName);
                    }

                    if (productVariantSampleDownload != null)
                    {
                        productVariantSampleDownload.UseDownloadUrl = useSampleDownloadURL;
                        productVariantSampleDownload.DownloadUrl    = sampleDownloadURL;
                        productVariantSampleDownload.DownloadBinary = productVariantSampleDownloadBinary;
                        productVariantSampleDownload.ContentType    = sampleDownloadContentType;
                        productVariantSampleDownload.Filename       = sampleDownloadFilename;
                        productVariantSampleDownload.Extension      = sampleDownloadExtension;
                        productVariantSampleDownload.IsNew          = true;
                        this.DownloadService.UpdateDownload(productVariantSampleDownload);
                    }
                    else
                    {
                        productVariantSampleDownload = new Download()
                        {
                            UseDownloadUrl = useSampleDownloadURL,
                            DownloadUrl    = sampleDownloadURL,
                            DownloadBinary = productVariantSampleDownloadBinary,
                            ContentType    = sampleDownloadContentType,
                            Filename       = sampleDownloadFilename,
                            Extension      = sampleDownloadExtension,
                            IsNew          = true
                        };
                        this.DownloadService.InsertDownload(productVariantSampleDownload);
                    }

                    productVariantSampleDownloadId = productVariantSampleDownload.DownloadId;
                }


                productVariant.Name                        = name;
                productVariant.SKU                         = sku;
                productVariant.Description                 = description;
                productVariant.AdminComment                = adminComment;
                productVariant.ManufacturerPartNumber      = manufacturerPartNumber;
                productVariant.IsGiftCard                  = isGiftCard;
                productVariant.GiftCardType                = giftCardType;
                productVariant.IsDownload                  = isDownload;
                productVariant.DownloadId                  = productVariantDownloadId;
                productVariant.UnlimitedDownloads          = unlimitedDownloads;
                productVariant.MaxNumberOfDownloads        = maxNumberOfDownloads;
                productVariant.DownloadExpirationDays      = downloadExpirationDays;
                productVariant.DownloadActivationType      = (int)downloadActivationType;
                productVariant.HasSampleDownload           = hasSampleDownload;
                productVariant.SampleDownloadId            = productVariantSampleDownloadId;
                productVariant.HasUserAgreement            = hasUserAgreement;
                productVariant.UserAgreementText           = userAgreementText;
                productVariant.IsRecurring                 = isRecurring;
                productVariant.CycleLength                 = cycleLength;
                productVariant.CyclePeriod                 = (int)cyclePeriod;
                productVariant.TotalCycles                 = totalCycles;
                productVariant.IsShipEnabled               = isShipEnabled;
                productVariant.IsFreeShipping              = isFreeShipping;
                productVariant.AdditionalShippingCharge    = additionalShippingCharge;
                productVariant.IsTaxExempt                 = isTaxExempt;
                productVariant.TaxCategoryId               = taxCategoryId;
                productVariant.ManageInventory             = manageStock;
                productVariant.StockQuantity               = stockQuantity;
                productVariant.DisplayStockAvailability    = displayStockAvailability;
                productVariant.DisplayStockQuantity        = displayStockQuantity;
                productVariant.MinStockQuantity            = minStockQuantity;
                productVariant.LowStockActivityId          = (int)lowStockActivity;
                productVariant.NotifyAdminForQuantityBelow = notifyForQuantityBelow;
                productVariant.Backorders                  = backorders;
                productVariant.OrderMinimumQuantity        = orderMinimumQuantity;
                productVariant.OrderMaximumQuantity        = orderMaximumQuantity;
                productVariant.WarehouseId                 = warehouseId;
                productVariant.DisableBuyButton            = disableBuyButton;
                productVariant.CallForPrice                = callForPrice;
                productVariant.Price                       = price;
                productVariant.OldPrice                    = oldPrice;
                productVariant.ProductCost                 = productCost;
                productVariant.CustomerEntersPrice         = customerEntersPrice;
                productVariant.MinimumCustomerEnteredPrice = minimumCustomerEnteredPrice;
                productVariant.MaximumCustomerEnteredPrice = maximumCustomerEnteredPrice;
                productVariant.Weight                      = weight;
                productVariant.Length                      = length;
                productVariant.Width                       = width;
                productVariant.Height                      = height;
                productVariant.PictureId                   = productVariantPictureId;
                productVariant.AvailableStartDateTime      = availableStartDateTime;
                productVariant.AvailableEndDateTime        = availableEndDateTime;
                productVariant.Published                   = published;
                productVariant.DisplayOrder                = displayOrder;
                productVariant.UpdatedOn                   = nowDT;

                this.ProductService.UpdateProductVariant(productVariant);

                #endregion
            }
            else
            {
                #region Insert
                Product product = this.ProductService.GetProductById(this.ProductId);
                if (product != null)
                {
                    Picture        productVariantPicture     = null;
                    HttpPostedFile productVariantPictureFile = fuProductVariantPicture.PostedFile;
                    if ((productVariantPictureFile != null) && (!String.IsNullOrEmpty(productVariantPictureFile.FileName)))
                    {
                        byte[] productVariantPictureBinary = productVariantPictureFile.GetPictureBits();
                        productVariantPicture = this.PictureService.InsertPicture(productVariantPictureBinary, productVariantPictureFile.ContentType, true);
                    }
                    int productVariantPictureId = 0;
                    if (productVariantPicture != null)
                    {
                        productVariantPictureId = productVariantPicture.PictureId;
                    }

                    int productVariantDownloadId = 0;
                    if (isDownload)
                    {
                        bool   useDownloadURL = cbUseDownloadURL.Checked;
                        string downloadURL    = txtDownloadURL.Text.Trim();
                        byte[] productVariantDownloadBinary = null;
                        string downloadContentType          = string.Empty;
                        string downloadFilename             = string.Empty;
                        string downloadExtension            = string.Empty;

                        HttpPostedFile productVariantDownloadFile = fuProductVariantDownload.PostedFile;
                        if ((productVariantDownloadFile != null) && (!String.IsNullOrEmpty(productVariantDownloadFile.FileName)))
                        {
                            productVariantDownloadBinary = productVariantDownloadFile.GetDownloadBits();
                            downloadContentType          = productVariantDownloadFile.ContentType;
                            downloadFilename             = Path.GetFileNameWithoutExtension(productVariantDownloadFile.FileName);
                            downloadExtension            = Path.GetExtension(productVariantDownloadFile.FileName);
                        }


                        var productVariantDownload = new Download()
                        {
                            UseDownloadUrl = useDownloadURL,
                            DownloadUrl    = downloadURL,
                            DownloadBinary = productVariantDownloadBinary,
                            ContentType    = downloadContentType,
                            Filename       = downloadFilename,
                            Extension      = downloadExtension,
                            IsNew          = true
                        };
                        this.DownloadService.InsertDownload(productVariantDownload);
                        productVariantDownloadId = productVariantDownload.DownloadId;
                    }

                    int productVariantSampleDownloadId = 0;
                    if (hasSampleDownload)
                    {
                        bool   useSampleDownloadURL = cbUseSampleDownloadURL.Checked;
                        string sampleDownloadURL    = txtSampleDownloadURL.Text.Trim();
                        byte[] productVariantSampleDownloadBinary = null;
                        string sampleDownloadContentType          = string.Empty;
                        string sampleDownloadFilename             = string.Empty;
                        string sampleDownloadExtension            = string.Empty;

                        HttpPostedFile productVariantSampleDownloadFile = fuProductVariantSampleDownload.PostedFile;
                        if ((productVariantSampleDownloadFile != null) && (!String.IsNullOrEmpty(productVariantSampleDownloadFile.FileName)))
                        {
                            productVariantSampleDownloadBinary = productVariantSampleDownloadFile.GetDownloadBits();
                            sampleDownloadContentType          = productVariantSampleDownloadFile.ContentType;
                            sampleDownloadFilename             = Path.GetFileNameWithoutExtension(productVariantSampleDownloadFile.FileName);
                            sampleDownloadExtension            = Path.GetExtension(productVariantSampleDownloadFile.FileName);
                        }

                        var productVariantSampleDownload = new Download()
                        {
                            UseDownloadUrl = useSampleDownloadURL,
                            DownloadUrl    = sampleDownloadURL,
                            DownloadBinary = productVariantSampleDownloadBinary,
                            ContentType    = sampleDownloadContentType,
                            Filename       = sampleDownloadFilename,
                            Extension      = sampleDownloadExtension,
                            IsNew          = true
                        };
                        this.DownloadService.InsertDownload(productVariantSampleDownload);
                        productVariantSampleDownloadId = productVariantSampleDownload.DownloadId;
                    }

                    productVariant = new ProductVariant()
                    {
                        ProductId                   = product.ProductId,
                        Name                        = name,
                        SKU                         = sku,
                        Description                 = description,
                        AdminComment                = adminComment,
                        ManufacturerPartNumber      = manufacturerPartNumber,
                        IsGiftCard                  = isGiftCard,
                        GiftCardType                = giftCardType,
                        IsDownload                  = isDownload,
                        DownloadId                  = productVariantDownloadId,
                        UnlimitedDownloads          = unlimitedDownloads,
                        MaxNumberOfDownloads        = maxNumberOfDownloads,
                        DownloadExpirationDays      = downloadExpirationDays,
                        DownloadActivationType      = (int)downloadActivationType,
                        HasSampleDownload           = hasSampleDownload,
                        SampleDownloadId            = productVariantSampleDownloadId,
                        HasUserAgreement            = hasUserAgreement,
                        UserAgreementText           = userAgreementText,
                        IsRecurring                 = isRecurring,
                        CycleLength                 = cycleLength,
                        CyclePeriod                 = (int)cyclePeriod,
                        TotalCycles                 = totalCycles,
                        IsShipEnabled               = isShipEnabled,
                        IsFreeShipping              = isFreeShipping,
                        AdditionalShippingCharge    = additionalShippingCharge,
                        IsTaxExempt                 = isTaxExempt,
                        TaxCategoryId               = taxCategoryId,
                        ManageInventory             = manageStock,
                        StockQuantity               = stockQuantity,
                        DisplayStockAvailability    = displayStockAvailability,
                        DisplayStockQuantity        = displayStockQuantity,
                        MinStockQuantity            = minStockQuantity,
                        LowStockActivityId          = (int)lowStockActivity,
                        NotifyAdminForQuantityBelow = notifyForQuantityBelow,
                        Backorders                  = backorders,
                        OrderMinimumQuantity        = orderMinimumQuantity,
                        OrderMaximumQuantity        = orderMaximumQuantity,
                        WarehouseId                 = warehouseId,
                        DisableBuyButton            = disableBuyButton,
                        CallForPrice                = callForPrice,
                        Price                       = price,
                        OldPrice                    = oldPrice,
                        ProductCost                 = productCost,
                        CustomerEntersPrice         = customerEntersPrice,
                        MinimumCustomerEnteredPrice = minimumCustomerEnteredPrice,
                        MaximumCustomerEnteredPrice = maximumCustomerEnteredPrice,
                        Weight                      = weight,
                        Length                      = length,
                        Width                       = width,
                        Height                      = height,
                        PictureId                   = productVariantPictureId,
                        AvailableStartDateTime      = availableStartDateTime,
                        AvailableEndDateTime        = availableEndDateTime,
                        Published                   = published,
                        Deleted                     = false,
                        DisplayOrder                = displayOrder,
                        CreatedOn                   = nowDT,
                        UpdatedOn                   = nowDT
                    };

                    this.ProductService.InsertProductVariant(productVariant);
                }
                else
                {
                    Response.Redirect("Products.aspx");
                }
                #endregion
            }

            SaveLocalizableContent(productVariant);

            return(productVariant);
        }