Ejemplo n.º 1
0
    private int CreateMenuItem()
    {
        ValidateData();

        var mItem = new AdvMenuItem
        {
            MenuItemName     = txtName.Text,
            MenuItemParentID = string.IsNullOrEmpty(hParent.Value) ? 0 : Convert.ToInt32(hParent.Value),
            MenuItemUrlPath  = txtUrl.Text,
            Enabled          = ckbEnabled.Checked,
            Blank            = ckbBlank.Checked,
            SortOrder        = Convert.ToInt32(txtSortOrder.Text),
            MenuItemUrlType  = (EMenuItemUrlType)Convert.ToInt32(rblLinkType.SelectedValue),
            ShowMode         = (EMenuItemShowMode)Convert.ToInt32(ddlShowMode.SelectedValue)
        };

        if (_type == MenuService.EMenuType.Top)
        {
            CacheManager.RemoveByPattern(CacheNames.GetMainMenuCacheObjectName());
            CacheManager.RemoveByPattern(CacheNames.GetMainMenuAuthCacheObjectName());
        }
        else if (_type == MenuService.EMenuType.Bottom)
        {
            var cacheName = CacheNames.GetBottomMenuCacheObjectName();
            if (CacheManager.Contains(cacheName))
            {
                CacheManager.Remove(cacheName);
            }

            var cacheAuthName = CacheNames.GetBottomMenuAuthCacheObjectName();
            if (CacheManager.Contains(cacheAuthName))
            {
                CacheManager.Remove(cacheAuthName);
            }
        }
        mItem.MenuItemID = MenuService.AddMenuItem(mItem, _type);
        _menuItemId      = mItem.MenuItemID;
        if (IconFileUpload.HasFile)
        {
            using (IconFileUpload.FileContent)
            {
                var tempName = PhotoService.AddPhoto(new Photo(0, _menuItemId, PhotoType.MenuIcon)
                {
                    OriginName = IconFileUpload.FileName
                });
                if (!string.IsNullOrWhiteSpace(tempName))
                {
                    IconFileUpload.SaveAs(FoldersHelper.GetPathAbsolut(FolderType.MenuIcons, tempName));
                }
            }
        }
        else
        {
            mItem.MenuItemIcon = string.Empty;
        }

        MenuService.UpdateMenuItem(mItem, _type);

        return(mItem.MenuItemID);
    }
Ejemplo n.º 2
0
        private void SaveMenuItem()
        {
            if (_mode == eMenuMode.Err)
            {
                return;
            }
            if (!ValidateData())
            {
                return;
            }
            var url = string.Empty;

            if (txtUrl.Text.Contains("www."))
            {
                url = txtUrl.Text.Contains("http://") || txtUrl.Text.Contains("https://") ? txtUrl.Text : "http://" + txtUrl.Text;
            }
            else
            {
                url = txtUrl.Text;
            }

            lblError.Text = String.Empty;
            var mItem = new AdvMenuItem
            {
                MenuItemID       = _menuItemId,
                MenuItemName     = txtName.Text,
                MenuItemParentID = string.IsNullOrEmpty(hParent.Value) ? 0 : Convert.ToInt32(hParent.Value),
                MenuItemUrlPath  = url,
                SortOrder        = Convert.ToInt32(txtSortOrder.Text),
                Blank            = ckbBlank.Checked,
                Enabled          = ckbEnabled.Checked,
                MenuItemUrlType  = (EMenuItemUrlType)Convert.ToInt32(rblLinkType.SelectedValue),
                ShowMode         = (EMenuItemShowMode)Convert.ToInt32(ddlShowMode.SelectedValue),
                NoFollow         = ckbNofollow.Checked
            };

            if (IconFileUpload.HasFile)
            {
                PhotoService.DeletePhotos(_menuItemId, PhotoType.MenuIcon);
                using (IconFileUpload.FileContent)
                {
                    var tempName = PhotoService.AddPhoto(new Photo(0, _menuItemId, PhotoType.MenuIcon)
                    {
                        OriginName = IconFileUpload.FileName
                    });
                    if (!string.IsNullOrWhiteSpace(tempName))
                    {
                        IconFileUpload.SaveAs(FoldersHelper.GetPathAbsolut(FolderType.MenuIcons, tempName));
                    }
                    mItem.MenuItemIcon = tempName;
                }
            }
            else
            {
                mItem.MenuItemIcon = pnlIcon.Visible ? imgIcon.ToolTip : null;
            }

            MenuService.UpdateMenuItem(mItem, _type);
            if (_type == MenuService.EMenuType.Top)
            {
                CacheManager.RemoveByPattern(CacheNames.GetMainMenuCacheObjectName());
                CacheManager.RemoveByPattern(CacheNames.GetMainMenuAuthCacheObjectName());
            }
            else if (_type == MenuService.EMenuType.Bottom)
            {
                var cacheName = CacheNames.GetBottomMenuCacheObjectName();
                if (CacheManager.Contains(cacheName))
                {
                    CacheManager.Remove(cacheName);
                }

                var cacheAuthName = CacheNames.GetBottomMenuAuthCacheObjectName();
                if (CacheManager.Contains(cacheAuthName))
                {
                    CacheManager.Remove(cacheAuthName);
                }
            }
        }