protected void cmdUpload_Click(object sender, EventArgs e)
        {
            HttpPostedFile categoryPictureFile = fuNewPicture.PostedFile;

            if (!string.IsNullOrEmpty(fuNewPicture.FileName))
            {
                byte[] categoryPictureBinary = categoryPictureFile.GetPictureBits();

                Picture picture = this.PictureService.InsertPicture(categoryPictureBinary,
                                                                    categoryPictureFile.ContentType, true);

                if (picture != null)
                {
                    string redirectURL = Common.Utils.CommonHelper.ModifyQueryString(Request.Url.PathAndQuery, "PictureID=" + picture.PictureId.ToString(), null);
                    Response.Redirect(redirectURL);
                }
            }
        }
        public Category SaveInfo()
        {
            var category = this.CategoryService.GetCategoryById(this.CategoryId);

            if (category != null)
            {
                Picture        categoryPicture     = category.Picture;
                HttpPostedFile categoryPictureFile = fuCategoryPicture.PostedFile;
                if ((categoryPictureFile != null) && (!String.IsNullOrEmpty(categoryPictureFile.FileName)))
                {
                    byte[] categoryPictureBinary = categoryPictureFile.GetPictureBits();
                    if (categoryPicture != null)
                    {
                        categoryPicture = this.PictureService.UpdatePicture(categoryPicture.PictureId, categoryPictureBinary, categoryPictureFile.ContentType, true);
                    }
                    else
                    {
                        categoryPicture = this.PictureService.InsertPicture(categoryPictureBinary, categoryPictureFile.ContentType, true);
                    }
                }
                int categoryPictureId = 0;
                if (categoryPicture != null)
                {
                    categoryPictureId = categoryPicture.PictureId;
                }

                category.Name             = txtName.Text.Trim();
                category.Description      = txtDescription.Value;
                category.TemplateId       = int.Parse(this.ddlTemplate.SelectedItem.Value);
                category.ParentCategoryId = ParentCategory.SelectedCategoryId;
                category.PictureId        = categoryPictureId;
                category.PriceRanges      = txtPriceRanges.Text;
                category.ShowOnHomePage   = cbShowOnHomePage.Checked;
                category.Published        = cbPublished.Checked;
                category.DisplayOrder     = txtDisplayOrder.Value;
                category.UpdatedOn        = DateTime.UtcNow;

                this.CategoryService.UpdateCategory(category);
            }
            else
            {
                Picture        categoryPicture     = null;
                HttpPostedFile categoryPictureFile = fuCategoryPicture.PostedFile;
                if ((categoryPictureFile != null) && (!String.IsNullOrEmpty(categoryPictureFile.FileName)))
                {
                    byte[] categoryPictureBinary = categoryPictureFile.GetPictureBits();
                    categoryPicture = this.PictureService.InsertPicture(categoryPictureBinary, categoryPictureFile.ContentType, true);
                }
                int categoryPictureId = 0;
                if (categoryPicture != null)
                {
                    categoryPictureId = categoryPicture.PictureId;
                }

                DateTime nowDT = DateTime.UtcNow;

                category = new Category()
                {
                    Name             = txtName.Text.Trim(),
                    Description      = txtDescription.Value,
                    TemplateId       = int.Parse(this.ddlTemplate.SelectedItem.Value),
                    ParentCategoryId = ParentCategory.SelectedCategoryId,
                    PictureId        = categoryPictureId,
                    PageSize         = 10,
                    PriceRanges      = txtPriceRanges.Text,
                    ShowOnHomePage   = cbShowOnHomePage.Checked,
                    Published        = cbPublished.Checked,
                    DisplayOrder     = txtDisplayOrder.Value,
                    CreatedOn        = nowDT,
                    UpdatedOn        = nowDT
                };

                this.CategoryService.InsertCategory(category);
            }

            SaveLocalizableContent(category);

            return(category);
        }
示例#3
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);
        }
示例#4
0
        public Manufacturer SaveInfo()
        {
            var manufacturer = this.ManufacturerService.GetManufacturerById(this.ManufacturerId);

            if (manufacturer != null)
            {
                Picture        manufacturerPicture     = manufacturer.Picture;
                HttpPostedFile manufacturerPictureFile = fuManufacturerPicture.PostedFile;
                if ((manufacturerPictureFile != null) && (!String.IsNullOrEmpty(manufacturerPictureFile.FileName)))
                {
                    byte[] manufacturerPictureBinary = manufacturerPictureFile.GetPictureBits();
                    if (manufacturerPicture != null)
                    {
                        manufacturerPicture = this.PictureService.UpdatePicture(manufacturerPicture.PictureId, manufacturerPictureBinary, manufacturerPictureFile.ContentType, true);
                    }
                    else
                    {
                        manufacturerPicture = this.PictureService.InsertPicture(manufacturerPictureBinary, manufacturerPictureFile.ContentType, true);
                    }
                }
                int manufacturerPictureId = 0;
                if (manufacturerPicture != null)
                {
                    manufacturerPictureId = manufacturerPicture.PictureId;
                }

                manufacturer.Name         = txtName.Text;
                manufacturer.Description  = txtDescription.Value;
                manufacturer.TemplateId   = int.Parse(this.ddlTemplate.SelectedItem.Value);
                manufacturer.PictureId    = manufacturerPictureId;
                manufacturer.PriceRanges  = txtPriceRanges.Text;
                manufacturer.Published    = cbPublished.Checked;
                manufacturer.DisplayOrder = txtDisplayOrder.Value;
                manufacturer.UpdatedOn    = DateTime.UtcNow;
                this.ManufacturerService.UpdateManufacturer(manufacturer);
            }
            else
            {
                Picture        manufacturerPicture     = null;
                HttpPostedFile manufacturerPictureFile = fuManufacturerPicture.PostedFile;
                if ((manufacturerPictureFile != null) && (!String.IsNullOrEmpty(manufacturerPictureFile.FileName)))
                {
                    byte[] manufacturerPictureBinary = manufacturerPictureFile.GetPictureBits();
                    manufacturerPicture = this.PictureService.InsertPicture(manufacturerPictureBinary, manufacturerPictureFile.ContentType, true);
                }
                int manufacturerPictureId = 0;
                if (manufacturerPicture != null)
                {
                    manufacturerPictureId = manufacturerPicture.PictureId;
                }

                DateTime nowDt = DateTime.UtcNow;

                manufacturer = new Manufacturer()
                {
                    Name         = txtName.Text,
                    Description  = txtDescription.Value,
                    TemplateId   = int.Parse(this.ddlTemplate.SelectedItem.Value),
                    PictureId    = manufacturerPictureId,
                    PageSize     = 10,
                    PriceRanges  = txtPriceRanges.Text,
                    Published    = cbPublished.Checked,
                    DisplayOrder = txtDisplayOrder.Value,
                    CreatedOn    = nowDt,
                    UpdatedOn    = nowDt
                };
                this.ManufacturerService.InsertManufacturer(manufacturer);
            }

            SaveLocalizableContent(manufacturer);

            return(manufacturer);
        }