Beispiel #1
0
        private int SaveData()
        {
            if (!Page.IsValid)
            {
                return(-1);
            }

            try
            {
                if (field == null || field.CustomFieldId == -1)
                {
                    field        = new CustomField();
                    field.SiteId = siteSettings.SiteId;
                }

                if (!IsLanguageTab())
                {
                    field.Name           = txtName.Text.Trim();
                    field.DisplayName    = txtDisplayName.Text.Trim();
                    field.InvalidMessage = txtInvalidMessage.Text.Trim();
                }

                field.FeatureGuid          = Product.FeatureGuid;
                field.DataType             = Convert.ToInt32(ddlDataType.SelectedValue);
                field.FilterType           = Convert.ToInt32(ddlFilterType.SelectedValue);
                field.FieldType            = Convert.ToInt32(ddlFieldType.SelectedValue);
                field.Options              = chlOptions.Items.SelectedItemsToBinaryOrOperator();
                field.IsEnabled            = chkIsEnabled.Checked;
                field.IsRequired           = chkIsRequired.Checked;
                field.AllowComparing       = chkAllowComparing.Checked;
                field.ValidationExpression = txtValidationExpression.Text.Trim();

                if (field.Save())
                {
                    SaveContentLanguage(field.Guid);
                }

                if (customFieldId > 0)
                {
                    LogActivity.Write("Update custom field", field.Name);
                    message.SuccessMessage = ResourceHelper.GetResourceString("Resource", "UpdateSuccessMessage");
                }
                else
                {
                    LogActivity.Write("Create new custom field", field.Name);
                    message.SuccessMessage = ResourceHelper.GetResourceString("Resource", "InsertSuccessMessage");
                }

                foreach (ListItem li in cobZones.Items)
                {
                    Guid itemGuid = Guid.Empty;
                    foreach (ZoneItem item in lstZoneItems)
                    {
                        if (li.Value == item.ZoneGuid.ToString())
                        {
                            itemGuid = item.ItemGuid;
                            break;
                        }
                    }

                    if (li.Selected)
                    {
                        if (itemGuid == Guid.Empty)
                        {
                            ZoneItem zoneItem = new ZoneItem();
                            zoneItem.ItemGuid = field.Guid;
                            zoneItem.ZoneGuid = new Guid(li.Value);
                            zoneItem.Save();
                        }
                    }
                    else
                    {
                        if (itemGuid != Guid.Empty)
                        {
                            ZoneItem.Delete(new Guid(li.Value), itemGuid);
                        }
                    }
                }

                return(field.CustomFieldId);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }

            return(-1);
        }
Beispiel #2
0
        void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (!ProductPermission.CanDelete)
                {
                    SiteUtils.RedirectToEditAccessDeniedPage();
                    return;
                }

                bool isDeleted = false;

                foreach (GridDataItem data in grid.SelectedItems)
                {
                    int     productId = Convert.ToInt32(data.GetDataKeyValue("ProductId"));
                    Product product   = new Product(siteSettings.SiteId, productId);

                    if (product != null && product.ProductId != -1 && !product.IsDeleted)
                    {
                        if (product.ZoneId.ToString() != ddZones.SelectedValue && ddZones.SelectedValue != "-1")
                        {
                            ZoneSettings objZone = new ZoneSettings(siteSettings.SiteId, Convert.ToInt32(ddZones.SelectedValue));
                            if (objZone != null && objZone.ZoneId > 0)
                            {
                                ZoneItem zoneNews = new ZoneItem(objZone.ZoneGuid, product.ProductGuid);
                                ZoneItem.Delete(zoneNews.ZoneGuid, zoneNews.ItemGuid);
                            }
                        }
                        else
                        {
                            ContentDeleted.Create(siteSettings.SiteId, product.Title, "Product", typeof(ProductDeleted).AssemblyQualifiedName, product.ProductId.ToString(), Page.User.Identity.Name);

                            product.IsDeleted = true;

                            product.ContentChanged += new ContentChangedEventHandler(product_ContentChanged);

                            product.SaveDeleted();
                            LogActivity.Write("Delete product", product.Title);
                        }

                        //ContentDeleted.Create(siteSettings.SiteId, product.Title, "Product", typeof(ProductDeleted).AssemblyQualifiedName, product.ProductId.ToString(), Page.User.Identity.Name);

                        //product.IsDeleted = true;

                        //product.ContentChanged += new ContentChangedEventHandler(product_ContentChanged);

                        //product.SaveDeleted();
                        //LogActivity.Write("Delete product", product.Title);

                        isDeleted = true;
                    }
                }

                if (isDeleted)
                {
                    SiteUtils.QueueIndexing();
                    grid.Rebind();

                    message.SuccessMessage = ResourceHelper.GetResourceString("Resource", "DeleteSuccessMessage");
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }