Example #1
0
        /// <summary>
        /// Get low stock activity name
        /// </summary>
        /// <param name="lsa">Low stock activity</param>
        /// <returns>Low stock activity name</returns>
        public static string GetLowStockActivityName(this LowStockActivityEnum lsa)
        {
            string name = IoC.Resolve <ILocalizationManager>().GetLocaleResourceString(
                string.Format("LowStockActivity.{0}", (int)lsa),
                NopContext.Current.WorkingLanguage.LanguageId,
                true,
                CommonHelper.ConvertEnum(lsa.ToString()));

            return(name);
        }
        /// <summary>
        /// Updates the product variant
        /// </summary>
        /// <param name="ProductVariantID">The product variant identifier</param>
        /// <param name="ProductID">The product identifier</param>
        /// <param name="Name">The name</param>
        /// <param name="SKU">The SKU</param>
        /// <param name="Description">The description</param>
        /// <param name="AdminComment">The admin comment</param>
        /// <param name="ManufacturerPartNumber">The manufacturer part number</param>
        /// <param name="IsDownload">A value indicating whether the product variant is download</param>
        /// <param name="DownloadID">The download identifier</param>
        /// <param name="UnlimitedDownloads">The value indicating whether this downloadable product can be downloaded unlimited number of times</param>
        /// <param name="MaxNumberOfDownloads">The maximum number of downloads</param>
        /// <param name="HasSampleDownload">The value indicating whether the product variant has a sample download file</param>
        /// <param name="SampleDownloadID">The sample download identifier</param>
        /// <param name="IsShipEnabled">A value indicating whether the entity is ship enabled</param>
        /// <param name="IsFreeShipping">A value indicating whether the entity is free shipping</param>
        /// <param name="AdditionalShippingCharge">The additional shipping charge</param>
        /// <param name="IsTaxExempt">A value indicating whether the product variant is marked as tax exempt</param>
        /// <param name="TaxCategoryID">The tax category identifier</param>
        /// <param name="ManageInventory">The value indicating whether to manage inventory</param>
        /// <param name="StockQuantity">The stock quantity</param>
        /// <param name="MinStockQuantity">The minimum stock quantity</param>
        /// <param name="LowStockActivity">The low stock activity</param>
        /// <param name="NotifyAdminForQuantityBelow">The quantity when admin should be notified</param>
        /// <param name="OrderMinimumQuantity">The order minimum quantity</param>
        /// <param name="OrderMaximumQuantity">The order maximum quantity</param>
        /// <param name="WarehouseId">The warehouse identifier</param>
        /// <param name="DisableBuyButton">A value indicating whether to disable buy button</param>
        /// <param name="Price">The price</param>
        /// <param name="OldPrice">The old price</param>
        /// <param name="Weight">The weight</param>
        /// <param name="Length">The length</param>
        /// <param name="Width">The width</param>
        /// <param name="Height">The height</param>
        /// <param name="PictureID">The picture identifier</param>
        /// <param name="AvailableStartDateTime">The available start date and time</param>
        /// <param name="AvailableEndDateTime">The available end date and time</param>
        /// <param name="Published">A value indicating whether the entity is published</param>
        /// <param name="Deleted">A value indicating whether the entity has been deleted</param>
        /// <param name="DisplayOrder">The display order</param>
        /// <param name="CreatedOn">The date and time of instance creation</param>
        /// <param name="UpdatedOn">The date and time of instance update</param>
        /// <returns>Product variant</returns>
        public static ProductVariant UpdateProductVariant(int ProductVariantID, int ProductID, string Name, string SKU, string Description, string AdminComment,
            string ManufacturerPartNumber, bool IsDownload, int DownloadID,
            bool UnlimitedDownloads, int MaxNumberOfDownloads,
            bool HasSampleDownload, int SampleDownloadID, bool IsShipEnabled,
            bool IsFreeShipping, decimal AdditionalShippingCharge,
            bool IsTaxExempt, int TaxCategoryID, bool ManageInventory,
            int StockQuantity, int MinStockQuantity, LowStockActivityEnum LowStockActivity,
            int NotifyAdminForQuantityBelow, int OrderMinimumQuantity, int OrderMaximumQuantity,
            int WarehouseId, bool DisableBuyButton,
            decimal Price, decimal OldPrice, decimal Weight, decimal Length, decimal Width,
            decimal Height, int PictureID, DateTime? AvailableStartDateTime, DateTime? AvailableEndDateTime,
            bool Published, bool Deleted, int DisplayOrder,
            DateTime CreatedOn, DateTime UpdatedOn)
        {
            if (AvailableStartDateTime.HasValue)
                AvailableStartDateTime = DateTimeHelper.ConvertToUtcTime(AvailableStartDateTime.Value);
            if (AvailableEndDateTime.HasValue)
                AvailableEndDateTime = DateTimeHelper.ConvertToUtcTime(AvailableEndDateTime.Value);
            CreatedOn = DateTimeHelper.ConvertToUtcTime(CreatedOn);
            UpdatedOn = DateTimeHelper.ConvertToUtcTime(UpdatedOn);

            DBProductVariant dbItem = DBProviderManager<DBProductProvider>.Provider.UpdateProductVariant(ProductVariantID,
                ProductID, Name, SKU, Description, AdminComment,
                ManufacturerPartNumber, IsDownload, DownloadID, UnlimitedDownloads, MaxNumberOfDownloads,
                HasSampleDownload, SampleDownloadID, IsShipEnabled,
                IsFreeShipping, AdditionalShippingCharge, IsTaxExempt, TaxCategoryID, ManageInventory, StockQuantity,
                MinStockQuantity, (int)LowStockActivity, NotifyAdminForQuantityBelow,
                OrderMinimumQuantity, OrderMaximumQuantity, WarehouseId, DisableBuyButton,
                Price, OldPrice,
                Weight, Length, Width, Height, PictureID,
                AvailableStartDateTime, AvailableEndDateTime,
                Published, Deleted, DisplayOrder, CreatedOn, UpdatedOn);

            ProductVariant productVariant = DBMapping(dbItem);

            if (ProductManager.CacheEnabled)
            {
                NopCache.RemoveByPattern(PRODUCTS_PATTERN_KEY);
                NopCache.RemoveByPattern(PRODUCTVARIANTS_PATTERN_KEY);
                NopCache.RemoveByPattern(TIERPRICES_PATTERN_KEY);
            }

            return productVariant;
        }
        public ProductVariant SaveInfo()
        {
            DateTime nowDT = DateTime.Now;

            string  name                          = txtName.Text.Trim();
            string  sku                           = txtSKU.Text.Trim();
            string  description                   = txtDescription.Value.Trim();
            string  adminComment                  = txtAdminComment.Text.Trim();
            string  manufacturerPartNumber        = txtManufacturerPartNumber.Text.Trim();
            bool    isDownload                    = cbIsDownload.Checked;
            bool    unlimitedDownloads            = cbUnlimitedDownloads.Checked;
            int     maxNumberOfDownloads          = txtMaxNumberOfDownloads.Value;
            bool    hasSampleDownload             = cbHasSampleDownload.Checked;
            bool    isShipEnabled                 = cbIsShipEnabled.Checked;
            bool    isFreeShipping                = cbIsFreeShipping.Checked;
            decimal additionalShippingCharge      = txtAdditionalShippingCharge.Value;
            bool    isTaxExempt                   = cbIsTaxExempt.Checked;
            int     taxCategoryID                 = int.Parse(this.ddlTaxCategory.SelectedItem.Value);
            bool    manageStock                   = cbManageStock.Checked;
            int     stockQuantity                 = txtStockQuantity.Value;
            int     minStockQuantity              = txtMinStockQuantity.Value;
            LowStockActivityEnum lowStockActivity = (LowStockActivityEnum)Enum.ToObject(typeof(LowStockActivityEnum), int.Parse(this.ddlLowStockActivity.SelectedItem.Value));
            int      notifyForQuantityBelow       = txtNotifyForQuantityBelow.Value;
            int      orderMinimumQuantity         = txtOrderMinimumQuantity.Value;
            int      orderMaximumQuantity         = txtOrderMaximumQuantity.Value;
            int      warehouseID                  = int.Parse(this.ddlWarehouse.SelectedItem.Value);
            bool     disableBuyButton             = cbDisableBuyButton.Checked;
            decimal  price                        = txtPrice.Value;
            decimal  oldPrice                     = txtOldPrice.Value;
            decimal  weight                       = txtWeight.Value;
            decimal  length                       = txtLength.Value;
            decimal  width                        = txtWidth.Value;
            decimal  height                       = txtHeight.Value;
            DateTime?availableStartDateTime       = null;
            DateTime?availableEndDateTime         = null;
            DateTime availableStartDateTimeTmp    = nowDT;

            if (DateTime.TryParse(txtAvailableStartDateTime.Text, out availableStartDateTimeTmp))
            {
                availableStartDateTime = DateTime.SpecifyKind(availableStartDateTimeTmp, DateTimeKind.Utc);
            }
            DateTime availableEndDateTimeTmp = nowDT;

            if (DateTime.TryParse(txtAvailableEndDateTime.Text, out availableEndDateTimeTmp))
            {
                availableEndDateTime = DateTime.SpecifyKind(availableEndDateTimeTmp, DateTimeKind.Utc);
            }
            bool published    = cbPublished.Checked;
            int  displayOrder = txtDisplayOrder.Value;

            ProductVariant productVariant = ProductManager.GetProductVariantByID(ProductVariantID);

            if (productVariant != null)
            {
                #region Update
                Picture        productVariantPicture     = productVariant.Picture;
                HttpPostedFile productVariantPictureFile = fuProductVariantPicture.PostedFile;
                if ((productVariantPictureFile != null) && (!String.IsNullOrEmpty(productVariantPictureFile.FileName)))
                {
                    byte[] productVariantPictureBinary = PictureManager.GetPictureBits(productVariantPictureFile.InputStream, productVariantPictureFile.ContentLength);
                    if (productVariantPicture != null)
                    {
                        productVariantPicture = PictureManager.UpdatePicture(productVariantPicture.PictureID, productVariantPictureBinary, productVariantPictureFile.ContentType, true);
                    }
                    else
                    {
                        productVariantPicture = PictureManager.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   downloadExtension            = string.Empty;
                    if (productVariantDownload != null)
                    {
                        productVariantDownloadBinary = productVariantDownload.DownloadBinary;
                        downloadContentType          = productVariantDownload.ContentType;
                        downloadExtension            = productVariantDownload.Extension;
                    }

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

                    if (productVariantDownload != null)
                    {
                        productVariantDownload = DownloadManager.UpdateDownload(productVariantDownload.DownloadID, useDownloadURL, downloadURL, productVariantDownloadBinary, downloadContentType, downloadExtension, true);
                    }
                    else
                    {
                        productVariantDownload = DownloadManager.InsertDownload(useDownloadURL, downloadURL, productVariantDownloadBinary, downloadContentType, downloadExtension, true);
                    }

                    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   sampleDownloadExtension            = string.Empty;
                    if (productVariantSampleDownload != null)
                    {
                        productVariantSampleDownloadBinary = productVariantSampleDownload.DownloadBinary;
                        sampleDownloadContentType          = productVariantSampleDownload.ContentType;
                        sampleDownloadExtension            = productVariantSampleDownload.Extension;
                    }

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

                    if (productVariantSampleDownload != null)
                    {
                        productVariantSampleDownload = DownloadManager.UpdateDownload(productVariantSampleDownload.DownloadID, useSampleDownloadURL, sampleDownloadURL, productVariantSampleDownloadBinary, sampleDownloadContentType, sampleDownloadExtension, true);
                    }
                    else
                    {
                        productVariantSampleDownload = DownloadManager.InsertDownload(useSampleDownloadURL, sampleDownloadURL, productVariantSampleDownloadBinary, sampleDownloadContentType, sampleDownloadExtension, true);
                    }

                    productVariantSampleDownloadID = productVariantSampleDownload.DownloadID;
                }

                productVariant = ProductManager.UpdateProductVariant(ProductVariantID,
                                                                     productVariant.ProductID, name, sku, description, adminComment, manufacturerPartNumber,
                                                                     isDownload, productVariantDownloadID, unlimitedDownloads,
                                                                     maxNumberOfDownloads, hasSampleDownload, productVariantSampleDownloadID,
                                                                     isShipEnabled, isFreeShipping, additionalShippingCharge,
                                                                     isTaxExempt, taxCategoryID, manageStock, stockQuantity,
                                                                     minStockQuantity, lowStockActivity, notifyForQuantityBelow,
                                                                     orderMinimumQuantity, orderMaximumQuantity,
                                                                     warehouseID, disableBuyButton, price, oldPrice, weight, length,
                                                                     width, height, productVariantPictureID,
                                                                     availableStartDateTime, availableEndDateTime, published,
                                                                     productVariant.Deleted, displayOrder, productVariant.CreatedOn, nowDT);
                #endregion
            }
            else
            {
                #region Insert
                Product product = ProductManager.GetProductByID(this.ProductID);
                if (product != null)
                {
                    Picture        productVariantPicture     = null;
                    HttpPostedFile productVariantPictureFile = fuProductVariantPicture.PostedFile;
                    if ((productVariantPictureFile != null) && (!String.IsNullOrEmpty(productVariantPictureFile.FileName)))
                    {
                        byte[] productVariantPictureBinary = PictureManager.GetPictureBits(productVariantPictureFile.InputStream, productVariantPictureFile.ContentLength);
                        productVariantPicture = PictureManager.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 downloadExtension            = string.Empty;

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

                        Download productVariantDownload = DownloadManager.InsertDownload(useDownloadURL, downloadURL, productVariantDownloadBinary, downloadContentType, downloadExtension, true);
                        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 sampleDownloadExtension            = string.Empty;

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

                        Download productVariantSampleDownload = DownloadManager.InsertDownload(useSampleDownloadURL, sampleDownloadURL, productVariantSampleDownloadBinary, sampleDownloadContentType, sampleDownloadExtension, true);
                        productVariantSampleDownloadID = productVariantSampleDownload.DownloadID;
                    }

                    productVariant = ProductManager.InsertProductVariant(product.ProductID,
                                                                         name, sku, description, adminComment, manufacturerPartNumber,
                                                                         isDownload, productVariantDownloadID, unlimitedDownloads,
                                                                         maxNumberOfDownloads, hasSampleDownload, productVariantSampleDownloadID,
                                                                         isShipEnabled, isFreeShipping, additionalShippingCharge, isTaxExempt, taxCategoryID,
                                                                         cbManageStock.Checked, txtStockQuantity.Value,
                                                                         minStockQuantity, lowStockActivity, notifyForQuantityBelow,
                                                                         orderMinimumQuantity, orderMaximumQuantity,
                                                                         warehouseID, disableBuyButton, price, oldPrice, weight,
                                                                         length, width, height, productVariantPictureID,
                                                                         availableStartDateTime, availableEndDateTime, published,
                                                                         false, displayOrder, nowDT, nowDT);
                }
                else
                {
                    Response.Redirect("Products.aspx");
                }
                #endregion
            }
            return(productVariant);
        }
Example #4
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);
        }
Example #5
0
        public Product SaveInfo()
        {
            DateTime nowDT = DateTime.UtcNow;

            string name                 = txtName.Text.Trim();
            string shortDescription     = txtShortDescription.Text.Trim();
            string fullDescription      = txtFullDescription.Content.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 = DownloadManager.GetDownloadBits(productVariantDownloadFile.InputStream, productVariantDownloadFile.ContentLength);
                    downloadContentType          = productVariantDownloadFile.ContentType;
                    downloadFilename             = Path.GetFileNameWithoutExtension(productVariantDownloadFile.FileName);
                    downloadExtension            = Path.GetExtension(productVariantDownloadFile.FileName);
                }

                Download productVariantDownload = DownloadManager.InsertDownload(useDownloadURL,
                                                                                 downloadURL, productVariantDownloadBinary, downloadContentType,
                                                                                 downloadFilename, downloadExtension, true);
                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.Content;

            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 = DownloadManager.GetDownloadBits(productVariantSampleDownloadFile.InputStream, productVariantSampleDownloadFile.ContentLength);
                    sampleDownloadContentType          = productVariantSampleDownloadFile.ContentType;
                    sampleDownloadFilename             = Path.GetFileNameWithoutExtension(productVariantSampleDownloadFile.FileName);
                    sampleDownloadExtension            = Path.GetExtension(productVariantSampleDownloadFile.FileName);
                }

                Download productVariantSampleDownload = DownloadManager.InsertDownload(useSampleDownloadURL,
                                                                                       sampleDownloadURL, productVariantSampleDownloadBinary, sampleDownloadContentType,
                                                                                       sampleDownloadFilename, sampleDownloadExtension, true);
                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 product = ProductManager.InsertProduct(name, shortDescription, fullDescription,
                                                           adminComment, templateId, showOnHomePage, string.Empty, string.Empty,
                                                           string.Empty, string.Empty, allowCustomerReviews, allowCustomerRatings, 0, 0,
                                                           published, false, nowDT, nowDT);

            ProductVariant productVariant = ProductManager.InsertProductVariant(product.ProductId,
                                                                                string.Empty, sku, string.Empty, string.Empty, manufacturerPartNumber,
                                                                                isGiftCard, giftCardType, isDownload, productVariantDownloadId, unlimitedDownloads,
                                                                                maxNumberOfDownloads, downloadExpirationDays, downloadActivationType,
                                                                                hasSampleDownload, productVariantSampleDownloadId,
                                                                                hasUserAgreement, userAgreementText,
                                                                                isRecurring, cycleLength, (int)cyclePeriod, totalCycles,
                                                                                isShipEnabled, isFreeShipping, additionalShippingCharge, isTaxExempt,
                                                                                taxCategoryId, manageStock, stockQuantity,
                                                                                displayStockAvailability, displayStockQuantity,
                                                                                minStockQuantity, lowStockActivity, notifyForQuantityBelow, backorders,
                                                                                orderMinimumQuantity, orderMaximumQuantity, warehouseId, disableBuyButton,
                                                                                callForPrice, price, oldPrice, productCost, customerEntersPrice,
                                                                                minimumCustomerEnteredPrice, maximumCustomerEnteredPrice,
                                                                                weight, length, width, height, 0, availableStartDateTime, availableEndDateTime,
                                                                                published, false, 1, nowDT, nowDT);

            SaveLocalizableContent(product);

            //product tags
            var productTags1 = ProductManager.GetAllProductTags(product.ProductId, string.Empty);

            foreach (var productTag in productTags1)
            {
                ProductManager.RemoveProductTagMapping(product.ProductId, productTag.ProductTagId);
            }
            string[] productTagNames = ParseProductTags(txtProductTags.Text);
            foreach (string productTagName in productTagNames)
            {
                ProductTag productTag   = null;
                var        productTags2 = ProductManager.GetAllProductTags(0,
                                                                           productTagName);
                if (productTags2.Count == 0)
                {
                    productTag = ProductManager.InsertProductTag(productTagName, 0);
                }
                else
                {
                    productTag = productTags2[0];
                }
                ProductManager.AddProductTagMapping(product.ProductId, productTag.ProductTagId);
            }

            return(product);
        }
Example #6
0
        public Product SaveInfo()
        {
            DateTime nowDT = DateTime.Now;

            string name                 = txtName.Text.Trim();
            string shortDescription     = txtShortDescription.Text.Trim();
            string fullDescription      = txtFullDescription.Value.Trim();
            string adminComment         = txtAdminComment.Text.Trim();
            int    productTypeID        = int.Parse(this.ddlProductType.SelectedItem.Value);
            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   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 downloadExtension            = string.Empty;

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

                Download productVariantDownload = DownloadManager.InsertDownload(useDownloadURL, downloadURL, productVariantDownloadBinary, downloadContentType, downloadExtension, true);
                productVariantDownloadID = productVariantDownload.DownloadID;
            }

            bool unlimitedDownloads   = cbUnlimitedDownloads.Checked;
            int  maxNumberOfDownloads = txtMaxNumberOfDownloads.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 sampleDownloadExtension            = string.Empty;

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

                Download productVariantSampleDownload = DownloadManager.InsertDownload(useSampleDownloadURL, sampleDownloadURL, productVariantSampleDownloadBinary, sampleDownloadContentType, sampleDownloadExtension, true);
                productVariantSampleDownloadID = productVariantSampleDownload.DownloadID;
            }

            bool    isShipEnabled            = cbIsShipEnabled.Checked;
            bool    isFreeShipping           = cbIsFreeShipping.Checked;
            decimal additionalShippingCharge = txtAdditionalShippingCharge.Value;
            bool    isTaxExempt      = cbIsTaxExempt.Checked;
            int     taxCategoryID    = int.Parse(this.ddlTaxCategory.SelectedItem.Value);
            bool    manageStock      = cbManageStock.Checked;
            int     stockQuantity    = txtStockQuantity.Value;
            int     minStockQuantity = txtMinStockQuantity.Value;
            LowStockActivityEnum lowStockActivity = (LowStockActivityEnum)Enum.ToObject(typeof(LowStockActivityEnum), int.Parse(this.ddlLowStockActivity.SelectedItem.Value));
            int      notifyForQuantityBelow       = txtNotifyForQuantityBelow.Value;
            int      orderMinimumQuantity         = txtOrderMinimumQuantity.Value;
            int      orderMaximumQuantity         = txtOrderMaximumQuantity.Value;
            int      warehouseID               = int.Parse(this.ddlWarehouse.SelectedItem.Value);
            bool     disableBuyButton          = cbDisableBuyButton.Checked;
            decimal  price                     = txtPrice.Value;
            decimal  oldPrice                  = txtOldPrice.Value;
            decimal  weight                    = txtWeight.Value;
            decimal  length                    = txtLength.Value;
            decimal  width                     = txtWidth.Value;
            decimal  height                    = txtHeight.Value;
            DateTime?availableStartDateTime    = null;
            DateTime?availableEndDateTime      = null;
            DateTime availableStartDateTimeTmp = nowDT;

            if (DateTime.TryParse(txtAvailableStartDateTime.Text, out availableStartDateTimeTmp))
            {
                availableStartDateTime = DateTime.SpecifyKind(availableStartDateTimeTmp, DateTimeKind.Utc);
            }
            DateTime availableEndDateTimeTmp = nowDT;

            if (DateTime.TryParse(txtAvailableEndDateTime.Text, out availableEndDateTimeTmp))
            {
                availableEndDateTime = DateTime.SpecifyKind(availableEndDateTimeTmp, DateTimeKind.Utc);
            }

            Product product = ProductManager.InsertProduct(name, shortDescription, fullDescription,
                                                           adminComment, productTypeID, templateID, showOnHomePage, string.Empty, string.Empty,
                                                           string.Empty, string.Empty, allowCustomerReviews, allowCustomerRatings, 0, 0,
                                                           published, false, nowDT, nowDT);

            ProductVariant productVariant = ProductManager.InsertProductVariant(product.ProductID,
                                                                                string.Empty, sku, string.Empty, string.Empty, manufacturerPartNumber,
                                                                                isDownload, productVariantDownloadID, unlimitedDownloads,
                                                                                maxNumberOfDownloads, hasSampleDownload, productVariantSampleDownloadID,
                                                                                isShipEnabled, isFreeShipping, additionalShippingCharge, isTaxExempt,
                                                                                taxCategoryID, manageStock, stockQuantity,
                                                                                minStockQuantity, lowStockActivity, notifyForQuantityBelow,
                                                                                orderMinimumQuantity, orderMaximumQuantity, warehouseID, disableBuyButton,
                                                                                price, oldPrice, weight, length,
                                                                                width, height, 0, availableStartDateTime, availableEndDateTime,
                                                                                published, false, 1, nowDT, nowDT);

            return(product);
        }
Example #7
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);
        }
Example #8
0
        public ProductVariant SaveInfo()
        {
            DateTime nowDT = DateTime.UtcNow;

            string name                   = txtName.Text.Trim();
            string sku                    = txtSKU.Text.Trim();
            string description            = txtDescription.Content;
            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.Content;
            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 = ProductManager.GetProductVariantById(ProductVariantId);

            if (productVariant != null)
            {
                #region Update
                Picture        productVariantPicture     = productVariant.Picture;
                HttpPostedFile productVariantPictureFile = fuProductVariantPicture.PostedFile;
                if ((productVariantPictureFile != null) && (!String.IsNullOrEmpty(productVariantPictureFile.FileName)))
                {
                    byte[] productVariantPictureBinary = PictureManager.GetPictureBits(productVariantPictureFile.InputStream, productVariantPictureFile.ContentLength);
                    if (productVariantPicture != null)
                    {
                        productVariantPicture = PictureManager.UpdatePicture(productVariantPicture.PictureId, productVariantPictureBinary, productVariantPictureFile.ContentType, true);
                    }
                    else
                    {
                        productVariantPicture = PictureManager.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 = DownloadManager.GetDownloadBits(productVariantDownloadFile.InputStream, productVariantDownloadFile.ContentLength);
                        downloadContentType          = productVariantDownloadFile.ContentType;
                        downloadFilename             = Path.GetFileNameWithoutExtension(productVariantDownloadFile.FileName);
                        downloadExtension            = Path.GetExtension(productVariantDownloadFile.FileName);
                    }

                    if (productVariantDownload != null)
                    {
                        productVariantDownload = DownloadManager.UpdateDownload(productVariantDownload.DownloadId,
                                                                                useDownloadURL, downloadURL, productVariantDownloadBinary,
                                                                                downloadContentType, downloadFilename, downloadExtension, true);
                    }
                    else
                    {
                        productVariantDownload = DownloadManager.InsertDownload(useDownloadURL,
                                                                                downloadURL, productVariantDownloadBinary, downloadContentType,
                                                                                downloadFilename, downloadExtension, true);
                    }

                    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 = DownloadManager.GetDownloadBits(productVariantSampleDownloadFile.InputStream, productVariantSampleDownloadFile.ContentLength);
                        sampleDownloadContentType          = productVariantSampleDownloadFile.ContentType;
                        sampleDownloadFilename             = Path.GetFileNameWithoutExtension(productVariantSampleDownloadFile.FileName);
                        sampleDownloadExtension            = Path.GetExtension(productVariantSampleDownloadFile.FileName);
                    }

                    if (productVariantSampleDownload != null)
                    {
                        productVariantSampleDownload = DownloadManager.UpdateDownload(productVariantSampleDownload.DownloadId,
                                                                                      useSampleDownloadURL, sampleDownloadURL, productVariantSampleDownloadBinary,
                                                                                      sampleDownloadContentType, sampleDownloadFilename, sampleDownloadExtension, true);
                    }
                    else
                    {
                        productVariantSampleDownload = DownloadManager.InsertDownload(useSampleDownloadURL,
                                                                                      sampleDownloadURL, productVariantSampleDownloadBinary,
                                                                                      sampleDownloadContentType, sampleDownloadFilename, sampleDownloadExtension, true);
                    }

                    productVariantSampleDownloadId = productVariantSampleDownload.DownloadId;
                }

                productVariant = ProductManager.UpdateProductVariant(ProductVariantId,
                                                                     productVariant.ProductId, name, sku, description, adminComment, manufacturerPartNumber,
                                                                     isGiftCard, giftCardType, isDownload, productVariantDownloadId, unlimitedDownloads,
                                                                     maxNumberOfDownloads, downloadExpirationDays, downloadActivationType,
                                                                     hasSampleDownload, productVariantSampleDownloadId, hasUserAgreement, userAgreementText,
                                                                     isRecurring, cycleLength, (int)cyclePeriod, totalCycles,
                                                                     isShipEnabled, isFreeShipping, additionalShippingCharge,
                                                                     isTaxExempt, taxCategoryId, manageStock, stockQuantity,
                                                                     displayStockAvailability, displayStockQuantity,
                                                                     minStockQuantity, lowStockActivity, notifyForQuantityBelow,
                                                                     backorders, orderMinimumQuantity, orderMaximumQuantity,
                                                                     warehouseId, disableBuyButton, callForPrice, price,
                                                                     oldPrice, productCost, customerEntersPrice,
                                                                     minimumCustomerEnteredPrice, maximumCustomerEnteredPrice,
                                                                     weight, length, width, height, productVariantPictureId,
                                                                     availableStartDateTime, availableEndDateTime, published,
                                                                     productVariant.Deleted, displayOrder, productVariant.CreatedOn, nowDT);
                #endregion
            }
            else
            {
                #region Insert
                Product product = ProductManager.GetProductById(this.ProductId);
                if (product != null)
                {
                    Picture        productVariantPicture     = null;
                    HttpPostedFile productVariantPictureFile = fuProductVariantPicture.PostedFile;
                    if ((productVariantPictureFile != null) && (!String.IsNullOrEmpty(productVariantPictureFile.FileName)))
                    {
                        byte[] productVariantPictureBinary = PictureManager.GetPictureBits(productVariantPictureFile.InputStream, productVariantPictureFile.ContentLength);
                        productVariantPicture = PictureManager.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 = DownloadManager.GetDownloadBits(productVariantDownloadFile.InputStream, productVariantDownloadFile.ContentLength);
                            downloadContentType          = productVariantDownloadFile.ContentType;
                            downloadFilename             = Path.GetFileNameWithoutExtension(productVariantDownloadFile.FileName);
                            downloadExtension            = Path.GetExtension(productVariantDownloadFile.FileName);
                        }

                        Download productVariantDownload = DownloadManager.InsertDownload(useDownloadURL, downloadURL,
                                                                                         productVariantDownloadBinary, downloadContentType,
                                                                                         downloadFilename, downloadExtension, true);
                        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 = DownloadManager.GetDownloadBits(productVariantSampleDownloadFile.InputStream, productVariantSampleDownloadFile.ContentLength);
                            sampleDownloadContentType          = productVariantSampleDownloadFile.ContentType;
                            sampleDownloadFilename             = Path.GetFileNameWithoutExtension(productVariantSampleDownloadFile.FileName);
                            sampleDownloadExtension            = Path.GetExtension(productVariantSampleDownloadFile.FileName);
                        }

                        Download productVariantSampleDownload = DownloadManager.InsertDownload(useSampleDownloadURL,
                                                                                               sampleDownloadURL, productVariantSampleDownloadBinary,
                                                                                               sampleDownloadContentType, sampleDownloadFilename, sampleDownloadExtension, true);
                        productVariantSampleDownloadId = productVariantSampleDownload.DownloadId;
                    }

                    productVariant = ProductManager.InsertProductVariant(product.ProductId,
                                                                         name, sku, description, adminComment, manufacturerPartNumber,
                                                                         isGiftCard, giftCardType, isDownload, productVariantDownloadId, unlimitedDownloads,
                                                                         maxNumberOfDownloads, downloadExpirationDays, downloadActivationType,
                                                                         hasSampleDownload, productVariantSampleDownloadId,
                                                                         hasUserAgreement, userAgreementText,
                                                                         isRecurring, cycleLength, (int)cyclePeriod, totalCycles,
                                                                         isShipEnabled, isFreeShipping, additionalShippingCharge, isTaxExempt, taxCategoryId,
                                                                         manageStock, stockQuantity, displayStockAvailability, displayStockQuantity,
                                                                         minStockQuantity, lowStockActivity, notifyForQuantityBelow,
                                                                         backorders, orderMinimumQuantity, orderMaximumQuantity,
                                                                         warehouseId, disableBuyButton, callForPrice, price, oldPrice, productCost,
                                                                         customerEntersPrice, minimumCustomerEnteredPrice, maximumCustomerEnteredPrice,
                                                                         weight, length, width, height, productVariantPictureId,
                                                                         availableStartDateTime, availableEndDateTime, published,
                                                                         false, displayOrder, nowDT, nowDT);
                }
                else
                {
                    Response.Redirect("Products.aspx");
                }
                #endregion
            }

            SaveLocalizableContent(productVariant);

            return(productVariant);
        }