Exemplo n.º 1
0
        private void UpdateProduct(int productID)
        {
            CampaignsProduct product = CampaignsProductProvider
                                       .GetCampaignsProducts()
                                       .WhereEquals("NodeSiteID", CurrentSite.SiteID)
                                       .WhereEquals("CampaignsProductID", productID)
                                       .FirstOrDefault();

            if (product != null)
            {
                product.DocumentName   = ValidationHelper.GetString(txtShortDes.Text, string.Empty);
                product.QtyPerPack     = ValidationHelper.GetInteger(txtBundleQnt.Text, default(int));
                product.BrandID        = ValidationHelper.GetInteger(ddlBrand.SelectedValue, default(int));
                product.CategoryID     = ValidationHelper.GetInteger(ddlProdCategory.SelectedValue, default(int));
                product.EstimatedPrice = ValidationHelper.GetInteger(txtEstPrice.Text, default(int));
                product.ProductName    = ValidationHelper.GetString(txtShortDes.Text, string.Empty);
                product.State          = ValidationHelper.GetInteger(ddlState.SelectedValue, default(int));
                SKUInfo updateProduct = SKUInfoProvider.GetSKUs().WhereEquals("SKUID", product.NodeSKUID).FirstObject;
                if (updateProduct != null)
                {
                    if (productImage.HasFile)
                    {
                        if (updateProduct.SKUImagePath != string.Empty)
                        {
                            UploadImage.DeleteImage(updateProduct.SKUImagePath, libraryFolderName);
                        }
                        updateProduct.SKUImagePath = UploadImage.UploadImageToMeadiaLibrary(productImage, libraryFolderName);
                    }
                    updateProduct.SKUName             = ValidationHelper.GetString(txtShortDes.Text, string.Empty);
                    updateProduct.SKUShortDescription = ValidationHelper.GetString(txtShortDes.Text, string.Empty);
                    updateProduct.SKUDescription      = ValidationHelper.GetString(txtLongDes.Text, string.Empty);
                    updateProduct.SKUPrice            = ValidationHelper.GetDouble(txtActualPrice.Text, default(double));
                    updateProduct.SKUEnabled          = ValidationHelper.GetString(ddlStatus.SelectedValue, "1") == "1" ? true : false;
                    updateProduct.SKUSiteID           = CurrentSite.SiteID;
                    updateProduct.SKUProductType      = SKUProductTypeEnum.EProduct;
                    updateProduct.SKUAvailableItems   = ValidationHelper.GetInteger(txtQuantity.Text, 0);
                    updateProduct.SKUWeight           = ValidationHelper.GetDouble(txtWeight.Text, default(double));
                    updateProduct.SKUValidUntil       = ValidationHelper.GetDateTime(txtExpDate.Text, DateTime.MinValue);
                    SKUInfoProvider.SetSKUInfo(updateProduct);
                }
                product.Update();
                var saveproductID = ValidationHelper.GetInteger(product.CampaignsProductID, 0);
                UpdateAllocateProduct(saveproductID);
                lblSuccessMsg.Visible  = true;
                lblFailureText.Visible = false;
                EmptyFields(true);
                Response.Cookies["status"].Value    = QueryStringStatus.Updated;
                Response.Cookies["status"].HttpOnly = false;
                URLHelper.Redirect($"{CurrentDocument.Parent.DocumentUrlPath}?status={QueryStringStatus.Updated}");
            }
            else
            {
                lblFailureText.Visible = true;
            }
        }
    /// <summary>
    /// Update the product data.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            int          programID = ValidationHelper.GetInteger(ddlProgram.SelectedValue, 0);
            TreeProvider tree      = new TreeProvider(MembershipContext.AuthenticatedUser);
            if (ViewState["ProductNodeID"] != null)
            {
                CampaignsProduct product = CampaignsProductProvider.GetCampaignsProduct(ValidationHelper.GetInteger(ViewState["ProductNodeID"], 0), CurrentDocument.DocumentCulture, CurrentSiteName);
                if (product != null)
                {
                    string itemSpecsID, customItemSpecs;
                    GetItemSpecsValue(out itemSpecsID, out customItemSpecs);
                    product.DocumentName    = ValidationHelper.GetString(txtProductName.Text, string.Empty);
                    product.ProgramID       = ValidationHelper.GetInteger(ddlProgram.SelectedValue, 0);
                    product.State           = ValidationHelper.GetInteger(ddlState.SelectedValue, default(int));
                    product.BrandID         = ValidationHelper.GetInteger(ddlBrand.SelectedValue, default(int));
                    product.CategoryID      = ValidationHelper.GetInteger(ddlProductcategory.SelectedValue, 0);
                    product.QtyPerPack      = ValidationHelper.GetInteger(txtQty.Text, default(int));
                    product.ItemSpecs       = ValidationHelper.GetString(itemSpecsID, string.Empty);
                    product.CustomItemSpecs = ValidationHelper.GetString(customItemSpecs, string.Empty);
                    product.EstimatedPrice  = ValidationHelper.GetDouble(txtEstimatedprice.Text, default(double));
                    product.ProductName     = ValidationHelper.GetString(txtProductName.Text, string.Empty);
                    SKUInfo updateProduct = SKUInfoProvider.GetSKUs().WhereEquals("SKUID", product.NodeSKUID).FirstObject;
                    if (updateProduct != null)
                    {
                        if (productImage.HasFile)
                        {
                            string libraryFolderName = SettingsKeyInfoProvider.GetValue(CurrentSite.SiteName + ".KDA_ImagesFolderName");
                            if (updateProduct.SKUImagePath != string.Empty)
                            {
                                UploadImage.DeleteImage(updateProduct.SKUImagePath, libraryFolderName);
                            }
                            updateProduct.SKUImagePath = UploadImage.UploadImageToMeadiaLibrary(productImage, libraryFolderName);
                        }
                        updateProduct.SKUName             = ValidationHelper.GetString(txtProductName.Text, string.Empty);
                        updateProduct.SKUShortDescription = ValidationHelper.GetString(txtProductName.Text, string.Empty);
                        updateProduct.SKUDescription      = ValidationHelper.GetString(txtLongDescription.Text, string.Empty);
                        updateProduct.SKUValidUntil       = ValidationHelper.GetDate(txtExpireDate.Text, DateTime.MinValue);
                        updateProduct.SKUEnabled          = ValidationHelper.GetString(ddlStatus.SelectedValue, "1") == "1" ? true : false;
                        updateProduct.SKUSiteID           = CurrentSite.SiteID;
                        updateProduct.SKUProductType      = SKUProductTypeEnum.EProduct;
                        updateProduct.SKUPrice            = 0;
                        SKUInfoProvider.SetSKUInfo(updateProduct);
                    }
                    product.Update();
                }

                if (ViewState["ProgramID"] != null)
                {
                    if (ValidationHelper.GetInteger(ViewState["ProgramID"], 0) != programID)
                    {
                        var targetProgram = ProgramProvider.GetPrograms()
                                            .WhereEquals("NodeSiteID", CurrentSite.SiteID)
                                            .WhereEquals("ProgramID", programID)
                                            .Column("NodeID")
                                            .FirstOrDefault();
                        if (targetProgram != null)
                        {
                            var tagetDocument = DocumentHelper.GetDocument(targetProgram.NodeID, CurrentDocument.DocumentCulture, tree);
                            var targetPage    = tree.SelectSingleNode(SiteContext.CurrentSiteName, tagetDocument.NodeAliasPath, CurrentDocument.DocumentCulture);
                            if ((product != null) && (targetPage != null))
                            {
                                DocumentHelper.MoveDocument(product, targetPage, tree, true);
                            }
                        }
                    }
                }
                int capaignNodeID = ValidationHelper.GetInteger(Request.QueryString["camp"], default(int));
                var campDoc       = DocumentHelper.GetDocument(capaignNodeID, CurrentDocument.DocumentCulture, tree);
                if (campDoc != null)
                {
                    Response.Redirect($"{campDoc.DocumentUrlPath}?status={QueryStringStatus.Updated}");
                }
            }
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("CMSWebParts_Kadena_Campaign_Web_Form_AddCampaignProducts", "btnUpdate_Click", ex, CurrentSite.SiteID, ex.Message);
        }
    }