예제 #1
0
 /// <summary>
 /// Gets a download url for an admin area
 /// </summary>
 /// <param name="download">Download instance</param>
 /// <returns>Download url</returns>
 public static string GetAdminDownloadUrl(Download download)
 {
     if (download == null)
         throw new ArgumentNullException("download");
     string url = CommonHelper.GetStoreAdminLocation() + "GetDownloadAdmin.ashx?DownloadID=" + download.DownloadID;
     return url;
 }
예제 #2
0
        private static Download DBMapping(DBDownload dbItem)
        {
            if (dbItem == null)
                return null;

            Download item = new Download();
            item.DownloadID = dbItem.DownloadID;
            item.UseDownloadURL = dbItem.UseDownloadURL;
            item.DownloadURL = dbItem.DownloadURL;
            item.DownloadBinary = dbItem.DownloadBinary;
            item.ContentType = dbItem.ContentType;
            item.Extension = dbItem.Extension;
            item.IsNew = dbItem.IsNew;

            return item;
        }
예제 #3
0
        /// <summary>
        /// Creates a copy of product with all depended data
        /// </summary>
        /// <param name="productId">The product identifier</param>
        /// <param name="name">The name of product duplicate</param>
        /// <param name="isPublished">A value indicating whether the product duplicate should be published</param>
        /// <param name="copyImages">A value indicating whether the product images should be copied</param>
        /// <returns>Product entity</returns>
        public Product DuplicateProduct(int productId, string name,
            bool isPublished, bool copyImages)
        {
            var product = GetProductById(productId);
            if (product == null)
                return null;

            Product productCopy = null;
            //uncomment this line to support transactions
            //using (var scope = new System.Transactions.TransactionScope())
            {
                // product
                productCopy = new Product()
                {
                    Name = name,
                    ShortDescription = product.ShortDescription,
                    FullDescription = product.FullDescription,
                    AdminComment = product.AdminComment,
                    TemplateId = product.TemplateId,
                    ShowOnHomePage = product.ShowOnHomePage,
                    MetaKeywords = product.MetaKeywords,
                    MetaDescription = product.MetaDescription,
                    MetaTitle = product.MetaTitle,
                    SEName = product.SEName,
                    AllowCustomerReviews = product.AllowCustomerReviews,
                    AllowCustomerRatings = product.AllowCustomerRatings,
                    Published = isPublished,
                    Deleted = product.Deleted,
                    CreatedOn = DateTime.UtcNow,
                    UpdatedOn = DateTime.UtcNow
                };
                InsertProduct(productCopy);

                if (productCopy == null)
                    return null;

                var languages = IoC.Resolve<ILanguageService>().GetAllLanguages(true);

                //localization
                foreach (var lang in languages)
                {
                    var productLocalized = GetProductLocalizedByProductIdAndLanguageId(product.ProductId, lang.LanguageId);
                    if (productLocalized != null)
                    {
                        var productLocalizedCopy = new ProductLocalized()
                        {
                            ProductId = productCopy.ProductId,
                            LanguageId = productLocalized.LanguageId,
                            Name = productLocalized.Name,
                            ShortDescription = productLocalized.ShortDescription,
                            FullDescription = productLocalized.FullDescription,
                            MetaKeywords = productLocalized.MetaKeywords,
                            MetaDescription = productLocalized.MetaDescription,
                            MetaTitle = productLocalized.MetaTitle,
                            SEName = productLocalized.SEName
                        };
                        InsertProductLocalized(productLocalizedCopy);
                    }
                }

                // product pictures
                if (copyImages)
                {
                    foreach (var productPicture in product.ProductPictures)
                    {
                        var picture = productPicture.Picture;

                        var pictureCopy = IoC.Resolve<IPictureService>().InsertPicture(picture.PictureBinary,
                            picture.MimeType,
                            picture.IsNew);

                        InsertProductPicture(new ProductPicture()
                        {
                            ProductId = productCopy.ProductId,
                            PictureId = pictureCopy.PictureId,
                            DisplayOrder = productPicture.DisplayOrder
                        });
                    }
                }

                // product <-> categories mappings
                foreach (var productCategory in product.ProductCategories)
                {
                    var productCategoryCopy = new ProductCategory()
                    {
                        ProductId = productCopy.ProductId,
                        CategoryId = productCategory.CategoryId,
                        IsFeaturedProduct = productCategory.IsFeaturedProduct,
                        DisplayOrder = productCategory.DisplayOrder
                    };

                    IoC.Resolve<ICategoryService>().InsertProductCategory(productCategoryCopy);
                }

                // product <-> manufacturers mappings
                foreach (var productManufacturers in product.ProductManufacturers)
                {
                    var productManufacturerCopy = new ProductManufacturer()
                    {
                        ProductId = productCopy.ProductId,
                        ManufacturerId = productManufacturers.ManufacturerId,
                        IsFeaturedProduct = productManufacturers.IsFeaturedProduct,
                        DisplayOrder = productManufacturers.DisplayOrder
                    };

                    IoC.Resolve<IManufacturerService>().InsertProductManufacturer(productManufacturerCopy);
                }

                // product <-> releated products mappings
                foreach (var relatedProduct in product.RelatedProducts)
                {
                    InsertRelatedProduct(
                        new RelatedProduct()
                        {
                            ProductId1 = productCopy.ProductId,
                            ProductId2 = relatedProduct.ProductId2,
                            DisplayOrder = relatedProduct.DisplayOrder
                        });
                }

                // product specifications
                foreach (var productSpecificationAttribute in IoC.Resolve<ISpecificationAttributeService>().GetProductSpecificationAttributesByProductId(product.ProductId))
                {
                    var psaCopy = new ProductSpecificationAttribute()
                    {
                        ProductId = productCopy.ProductId,
                        SpecificationAttributeOptionId = productSpecificationAttribute.SpecificationAttributeOptionId,
                        AllowFiltering = productSpecificationAttribute.AllowFiltering,
                        ShowOnProductPage = productSpecificationAttribute.ShowOnProductPage,
                        DisplayOrder = productSpecificationAttribute.DisplayOrder
                    };
                    IoC.Resolve<ISpecificationAttributeService>().InsertProductSpecificationAttribute(psaCopy);
                }

                // product variants
                var productVariants = GetProductVariantsByProductId(product.ProductId, true);
                foreach (var productVariant in productVariants)
                {
                    // product variant picture
                    int pictureId = 0;
                    if (copyImages)
                    {
                        var picture = productVariant.Picture;
                        if (picture != null)
                        {
                            var pictureCopy = IoC.Resolve<IPictureService>().InsertPicture(picture.PictureBinary, picture.MimeType, picture.IsNew);
                            pictureId = pictureCopy.PictureId;
                        }
                    }

                    // product variant download & sample download
                    int downloadId = productVariant.DownloadId;
                    int sampleDownloadId = productVariant.SampleDownloadId;
                    if (productVariant.IsDownload)
                    {
                        var download = productVariant.Download;
                        if (download != null)
                        {
                            var downloadCopy = new Download()
                                {
                                    UseDownloadUrl = download.UseDownloadUrl,
                                    DownloadUrl = download.DownloadUrl,
                                    DownloadBinary = download.DownloadBinary,
                                    ContentType = download.ContentType,
                                    Filename = download.Filename,
                                    Extension = download.Extension,
                                    IsNew = download.IsNew
                                };
                            IoC.Resolve<IDownloadService>().InsertDownload(downloadCopy);
                            downloadId = downloadCopy.DownloadId;
                        }

                        if (productVariant.HasSampleDownload)
                        {
                            var sampleDownload = productVariant.SampleDownload;
                            if (sampleDownload != null)
                            {
                                var sampleDownloadCopy = new Download()
                                {
                                    UseDownloadUrl = sampleDownload.UseDownloadUrl,
                                    DownloadUrl = sampleDownload.DownloadUrl,
                                    DownloadBinary = sampleDownload.DownloadBinary,
                                    ContentType = sampleDownload.ContentType,
                                    Filename = sampleDownload.Filename,
                                    Extension = sampleDownload.Extension,
                                    IsNew = sampleDownload.IsNew
                                };
                                IoC.Resolve<IDownloadService>().InsertDownload(sampleDownloadCopy);
                                sampleDownloadId = sampleDownloadCopy.DownloadId;
                            }
                        }
                    }

                    // product variant
                    var productVariantCopy = new ProductVariant()
                    {
                        ProductId = productCopy.ProductId,
                        Name = productVariant.Name,
                        SKU = productVariant.SKU,
                        Description = productVariant.Description,
                        AdminComment = productVariant.AdminComment,
                        ManufacturerPartNumber = productVariant.ManufacturerPartNumber,
                        IsGiftCard = productVariant.IsGiftCard,
                        GiftCardType = productVariant.GiftCardType,
                        IsDownload = productVariant.IsDownload,
                        DownloadId = downloadId,
                        UnlimitedDownloads = productVariant.UnlimitedDownloads,
                        MaxNumberOfDownloads = productVariant.MaxNumberOfDownloads,
                        DownloadExpirationDays = productVariant.DownloadExpirationDays,
                        DownloadActivationType = productVariant.DownloadActivationType,
                        HasSampleDownload = productVariant.HasSampleDownload,
                        SampleDownloadId = sampleDownloadId,
                        HasUserAgreement = productVariant.HasUserAgreement,
                        UserAgreementText = productVariant.UserAgreementText,
                        IsRecurring = productVariant.IsRecurring,
                        CycleLength = productVariant.CycleLength,
                        CyclePeriod = productVariant.CyclePeriod,
                        TotalCycles = productVariant.TotalCycles,
                        IsShipEnabled = productVariant.IsShipEnabled,
                        IsFreeShipping = productVariant.IsFreeShipping,
                        AdditionalShippingCharge = productVariant.AdditionalShippingCharge,
                        IsTaxExempt = productVariant.IsTaxExempt,
                        TaxCategoryId = productVariant.TaxCategoryId,
                        ManageInventory = productVariant.ManageInventory,
                        StockQuantity = productVariant.StockQuantity,
                        DisplayStockAvailability = productVariant.DisplayStockAvailability,
                        DisplayStockQuantity = productVariant.DisplayStockQuantity,
                        MinStockQuantity = productVariant.MinStockQuantity,
                        LowStockActivityId = productVariant.LowStockActivityId,
                        NotifyAdminForQuantityBelow = productVariant.NotifyAdminForQuantityBelow,
                        Backorders = productVariant.Backorders,
                        OrderMinimumQuantity = productVariant.OrderMinimumQuantity,
                        OrderMaximumQuantity = productVariant.OrderMaximumQuantity,
                        WarehouseId = productVariant.WarehouseId,
                        DisableBuyButton = productVariant.DisableBuyButton,
                        CallForPrice = productVariant.CallForPrice,
                        Price = productVariant.Price,
                        OldPrice = productVariant.OldPrice,
                        ProductCost = productVariant.ProductCost,
                        CustomerEntersPrice = productVariant.CustomerEntersPrice,
                        MinimumCustomerEnteredPrice = productVariant.MinimumCustomerEnteredPrice,
                        MaximumCustomerEnteredPrice = productVariant.MaximumCustomerEnteredPrice,
                        Weight = productVariant.Weight,
                        Length = productVariant.Length,
                        Width = productVariant.Width,
                        Height = productVariant.Height,
                        PictureId = pictureId,
                        AvailableStartDateTime = productVariant.AvailableStartDateTime,
                        AvailableEndDateTime = productVariant.AvailableEndDateTime,
                        Published = productVariant.Published,
                        Deleted = productVariant.Deleted,
                        DisplayOrder = productVariant.DisplayOrder,
                        CreatedOn = DateTime.UtcNow,
                        UpdatedOn = DateTime.UtcNow
                    };

                    InsertProductVariant(productVariantCopy);

                    //localization
                    foreach (var lang in languages)
                    {
                        var productVariantLocalized = GetProductVariantLocalizedByProductVariantIdAndLanguageId(productVariant.ProductVariantId, lang.LanguageId);
                        if (productVariantLocalized != null)
                        {
                            var productVariantLocalizedCopy = new ProductVariantLocalized()
                            {
                                ProductVariantId = productVariantCopy.ProductVariantId,
                                LanguageId = productVariantLocalized.LanguageId,
                                Name = productVariantLocalized.Name,
                                Description = productVariantLocalized.Description
                            };
                            InsertProductVariantLocalized(productVariantLocalizedCopy);
                        }
                    }

                    // product variant <-> attributes mappings
                    foreach (var productVariantAttribute in IoC.Resolve<IProductAttributeService>().GetProductVariantAttributesByProductVariantId(productVariant.ProductVariantId))
                    {
                        var productVariantAttributeCopy = new ProductVariantAttribute()
                        {
                            ProductVariantId = productVariantCopy.ProductVariantId,
                            ProductAttributeId = productVariantAttribute.ProductAttributeId,
                            TextPrompt = productVariantAttribute.TextPrompt,
                            IsRequired = productVariantAttribute.IsRequired,
                            AttributeControlTypeId = productVariantAttribute.AttributeControlTypeId,
                            DisplayOrder = productVariantAttribute.DisplayOrder
                        };
                        IoC.Resolve<IProductAttributeService>().InsertProductVariantAttribute(productVariantAttributeCopy);

                        // product variant attribute values
                        var productVariantAttributeValues = IoC.Resolve<IProductAttributeService>().GetProductVariantAttributeValues(productVariantAttribute.ProductVariantAttributeId);
                        foreach (var productVariantAttributeValue in productVariantAttributeValues)
                        {
                            var pvavCopy = new ProductVariantAttributeValue()
                            {
                                ProductVariantAttributeId = productVariantAttributeCopy.ProductVariantAttributeId,
                                Name = productVariantAttributeValue.Name,
                                PriceAdjustment = productVariantAttributeValue.PriceAdjustment,
                                WeightAdjustment = productVariantAttributeValue.WeightAdjustment,
                                IsPreSelected = productVariantAttributeValue.IsPreSelected,
                                DisplayOrder = productVariantAttributeValue.DisplayOrder
                            };
                            IoC.Resolve<IProductAttributeService>().InsertProductVariantAttributeValue(pvavCopy);

                            //localization
                            foreach (var lang in languages)
                            {
                                var pvavLocalized = IoC.Resolve<IProductAttributeService>().GetProductVariantAttributeValueLocalizedByProductVariantAttributeValueIdAndLanguageId(productVariantAttributeValue.ProductVariantAttributeValueId, lang.LanguageId);
                                if (pvavLocalized != null)
                                {
                                    var pvavLocalizedCopy = new ProductVariantAttributeValueLocalized()
                                    {
                                        ProductVariantAttributeValueId = pvavCopy.ProductVariantAttributeValueId,
                                        LanguageId = pvavLocalized.LanguageId,
                                        Name = pvavLocalized.Name
                                    };
                                    IoC.Resolve<IProductAttributeService>().InsertProductVariantAttributeValueLocalized(pvavLocalizedCopy);
                                }
                            }
                        }
                    }
                    foreach (var combination in IoC.Resolve<IProductAttributeService>().GetAllProductVariantAttributeCombinations(productVariant.ProductVariantId))
                    {
                        var combinationCopy = new ProductVariantAttributeCombination()
                        {
                            ProductVariantId = productVariantCopy.ProductVariantId,
                            AttributesXml = combination.AttributesXml,
                            StockQuantity = combination.StockQuantity,
                            AllowOutOfStockOrders = combination.AllowOutOfStockOrders
                        };
                        IoC.Resolve<IProductAttributeService>().InsertProductVariantAttributeCombination(combinationCopy);
                    }

                    // product variant tier prices
                    foreach (var tierPrice in productVariant.TierPrices)
                    {
                        InsertTierPrice(
                            new TierPrice()
                            {
                                ProductVariantId = productVariantCopy.ProductVariantId,
                                Quantity = tierPrice.Quantity,
                                Price = tierPrice.Price
                            });
                    }

                    // product variant <-> discounts mapping
                    foreach (var discount in productVariant.AllDiscounts)
                    {
                        IoC.Resolve<IDiscountService>().AddDiscountToProductVariant(productVariantCopy.ProductVariantId, discount.DiscountId);
                    }

                    // prices by customer role
                    foreach (var crpp in productVariant.CustomerRoleProductPrices)
                    {
                        this.InsertCustomerRoleProductPrice(
                            new CustomerRoleProductPrice()
                            {
                                CustomerRoleId = crpp.CustomerRoleId,
                                ProductVariantId = productVariantCopy.ProductVariantId,
                                Price = crpp.Price
                            }
                            );
                    }
                }

                //uncomment this line to support transactions
                //scope.Complete();
            }

            return productCopy;
        }
        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;
        }
예제 #5
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;
        }
        protected void gvOrderProductVariants_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DownloadActivation")
            {
                //download activation
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = gvOrderProductVariants.Rows[index];
                HiddenField hfOrderProductVariantId = row.FindControl("hfOrderProductVariantId") as HiddenField;

                int orderProductVariantId = int.Parse(hfOrderProductVariantId.Value);
                OrderProductVariant orderProductVariant = this.OrderService.GetOrderProductVariantById(orderProductVariantId);

                if (orderProductVariant != null)
                {
                    orderProductVariant.IsDownloadActivated = !orderProductVariant.IsDownloadActivated;
                    this.OrderService.UpdateOrderProductVariant(orderProductVariant);
                }

            }
            else if (e.CommandName == "RemoveLicenseDownload")
            {
                //remove license download
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = gvOrderProductVariants.Rows[index];
                HiddenField hfOrderProductVariantId = row.FindControl("hfOrderProductVariantId") as HiddenField;

                int orderProductVariantId = int.Parse(hfOrderProductVariantId.Value);
                OrderProductVariant orderProductVariant = this.OrderService.GetOrderProductVariantById(orderProductVariantId);

                if (orderProductVariant != null)
                {
                    orderProductVariant.LicenseDownloadId = 0;
                    this.OrderService.UpdateOrderProductVariant(orderProductVariant);
                }
            }
            else if (e.CommandName == "UploadLicenseDownload")
            {
                //upload new license
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = gvOrderProductVariants.Rows[index];
                HiddenField hfOrderProductVariantId = row.FindControl("hfOrderProductVariantId") as HiddenField;

                int orderProductVariantId = int.Parse(hfOrderProductVariantId.Value);
                OrderProductVariant orderProductVariant = this.OrderService.GetOrderProductVariantById(orderProductVariantId);

                FileUpload fuLicenseDownload = row.FindControl("fuLicenseDownload") as FileUpload;
                HttpPostedFile licenseDownloadFile = fuLicenseDownload.PostedFile;
                if ((licenseDownloadFile != null) && (!String.IsNullOrEmpty(licenseDownloadFile.FileName)))
                {
                    byte[] licenseDownloadBinary = licenseDownloadFile.GetDownloadBits();
                    string downloadContentType = licenseDownloadFile.ContentType;
                    string downloadFilename = Path.GetFileNameWithoutExtension(licenseDownloadFile.FileName);
                    string downloadExtension = Path.GetExtension(licenseDownloadFile.FileName);

                    var licenseDownload = new Download()
                    {
                        UseDownloadUrl = false,
                        DownloadUrl = string.Empty,
                        DownloadBinary = licenseDownloadBinary,
                        ContentType = downloadContentType,
                        Filename = downloadFilename,
                        Extension = downloadExtension,
                        IsNew = true
                    };
                    this.DownloadService.InsertDownload(licenseDownload);

                    if (orderProductVariant != null)
                    {
                        orderProductVariant.LicenseDownloadId = licenseDownload.DownloadId;
                        this.OrderService.UpdateOrderProductVariant(orderProductVariant);
                    }
                }
            }
            else if (e.CommandName == "EditOpv")
            {
                try
                {
                    //edit order product variants
                    int index = Convert.ToInt32(e.CommandArgument);
                    GridViewRow row = gvOrderProductVariants.Rows[index];
                    HiddenField hfOrderProductVariantId = row.FindControl("hfOrderProductVariantId") as HiddenField;

                    int orderProductVariantId = int.Parse(hfOrderProductVariantId.Value);
                    OrderProductVariant orderProductVariant = this.OrderService.GetOrderProductVariantById(orderProductVariantId);

                    TextBox txtPvUnitPriceInclTax = row.FindControl("txtPvUnitPriceInclTax") as TextBox;
                    TextBox txtPvUnitPriceExclTax = row.FindControl("txtPvUnitPriceExclTax") as TextBox;
                    TextBox txtPvUnitPriceCustCurrencyInclTax = row.FindControl("txtPvUnitPriceCustCurrencyInclTax") as TextBox;
                    TextBox txtPvUnitPriceCustCurrencyExclTax = row.FindControl("txtPvUnitPriceCustCurrencyExclTax") as TextBox;
                    TextBox txtPvQuantity = row.FindControl("txtPvQuantity") as TextBox;
                    TextBox txtPvDiscountInclTax = row.FindControl("txtPvDiscountInclTax") as TextBox;
                    TextBox txtPvDiscountExclTax = row.FindControl("txtPvDiscountExclTax") as TextBox;
                    TextBox txtPvPriceInclTax = row.FindControl("txtPvPriceInclTax") as TextBox;
                    TextBox txtPvPriceExclTax = row.FindControl("txtPvPriceExclTax") as TextBox;
                    TextBox txtPvPriceCustCurrencyInclTax = row.FindControl("txtPvPriceCustCurrencyInclTax") as TextBox;
                    TextBox txtPvPriceCustCurrencyExclTax = row.FindControl("txtPvPriceCustCurrencyExclTax") as TextBox;

                    decimal unitPriceInclTax = orderProductVariant.UnitPriceInclTax;
                    decimal unitPriceExclTax = orderProductVariant.UnitPriceExclTax;
                    decimal unitPriceInclTaxInCustomerCurrency = orderProductVariant.UnitPriceInclTaxInCustomerCurrency;
                    decimal unitPriceExclTaxInCustomerCurrency = orderProductVariant.UnitPriceExclTaxInCustomerCurrency;
                    int quantity = orderProductVariant.Quantity;
                    decimal discountInclTax = orderProductVariant.DiscountAmountInclTax;
                    decimal discountExclTax = orderProductVariant.DiscountAmountExclTax;
                    decimal priceInclTax = orderProductVariant.PriceInclTax;
                    decimal priceExclTax = orderProductVariant.PriceExclTax;
                    decimal priceInclTaxInCustomerCurrency = orderProductVariant.PriceInclTaxInCustomerCurrency;
                    decimal priceExclTaxInCustomerCurrency = orderProductVariant.PriceExclTaxInCustomerCurrency;

                    unitPriceInclTax = decimal.Parse(txtPvUnitPriceInclTax.Text);
                    unitPriceExclTax = decimal.Parse(txtPvUnitPriceExclTax.Text);
                    unitPriceInclTaxInCustomerCurrency = decimal.Parse(txtPvUnitPriceCustCurrencyInclTax.Text);
                    unitPriceExclTaxInCustomerCurrency = decimal.Parse(txtPvUnitPriceCustCurrencyExclTax.Text);
                    quantity = int.Parse(txtPvQuantity.Text);
                    discountInclTax = decimal.Parse(txtPvDiscountInclTax.Text);
                    discountExclTax = decimal.Parse(txtPvDiscountExclTax.Text);
                    priceInclTax = decimal.Parse(txtPvPriceInclTax.Text);
                    priceExclTax = decimal.Parse(txtPvPriceExclTax.Text);
                    priceInclTaxInCustomerCurrency = decimal.Parse(txtPvPriceCustCurrencyInclTax.Text);
                    priceExclTaxInCustomerCurrency = decimal.Parse(txtPvPriceCustCurrencyExclTax.Text);

                    if (quantity > 0)
                    {
                        orderProductVariant.UnitPriceInclTax = unitPriceInclTax;
                        orderProductVariant.UnitPriceExclTax = unitPriceExclTax;
                        orderProductVariant.PriceInclTax = priceInclTax;
                        orderProductVariant.PriceExclTax = priceExclTax;
                        orderProductVariant.UnitPriceInclTaxInCustomerCurrency = unitPriceInclTaxInCustomerCurrency;
                        orderProductVariant.UnitPriceExclTaxInCustomerCurrency = unitPriceExclTaxInCustomerCurrency;
                        orderProductVariant.PriceInclTaxInCustomerCurrency = priceInclTaxInCustomerCurrency;
                        orderProductVariant.PriceExclTaxInCustomerCurrency = priceExclTaxInCustomerCurrency;
                        orderProductVariant.Quantity = quantity;
                        orderProductVariant.DiscountAmountInclTax = discountInclTax;
                        orderProductVariant.DiscountAmountExclTax = discountExclTax;
                        this.OrderService.UpdateOrderProductVariant(orderProductVariant);
                    }
                    else
                    {
                        this.OrderService.DeleteOrderProductVariant(orderProductVariant.OrderProductVariantId);
                    }
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
            else if (e.CommandName == "DeleteOpv")
            {
                try
                {
                    //edit order product variants
                    int index = Convert.ToInt32(e.CommandArgument);
                    GridViewRow row = gvOrderProductVariants.Rows[index];
                    HiddenField hfOrderProductVariantId = row.FindControl("hfOrderProductVariantId") as HiddenField;

                    int orderProductVariantId = int.Parse(hfOrderProductVariantId.Value);

                    this.OrderService.DeleteOrderProductVariant(orderProductVariantId);
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }

            BindData();
        }
예제 #7
0
        /// <summary>
        /// Updates the download
        /// </summary>
        /// <param name="download">Download</param>
        public void UpdateDownload(Download download)
        {
            if (download == null)
                throw new ArgumentNullException("download");

            download.DownloadUrl = CommonHelper.EnsureNotNull(download.DownloadUrl);
            download.DownloadUrl = CommonHelper.EnsureMaximumLength(download.DownloadUrl, 400);
            download.ContentType = CommonHelper.EnsureNotNull(download.ContentType);
            download.ContentType = CommonHelper.EnsureMaximumLength(download.ContentType, 20);
            download.Filename = CommonHelper.EnsureNotNull(download.Filename);
            download.Filename = CommonHelper.EnsureMaximumLength(download.Filename, 100);
            download.Extension = CommonHelper.EnsureNotNull(download.Extension);
            download.Extension = CommonHelper.EnsureMaximumLength(download.Extension, 20);

            if (!_context.IsAttached(download))
                _context.Downloads.Attach(download);

            _context.SaveChanges();
        }