Example #1
0
        public ActionResult Index(string submit, FormCollection formcollection)
        {
            string _strMenuClass = formcollection["MenuClass"] == null ? "" : formcollection["MenuClass"];
            string _strwhosubmit = formcollection["whosubmit"] == null ? "" : formcollection["whosubmit"];
            string _strMenuName  = formcollection["MenuName"] == null ? "" : formcollection["MenuName"];
            string _MenuNo       = formcollection["MenuNo"] == null ? "" : formcollection["MenuNo"];

            if (string.IsNullOrEmpty(_strMenuClass))
            {
                _strMenuClass = Request.QueryString["MenuClass"] == null ? "" : Request.QueryString["MenuClass"];
            }
            //新增
            if ((_strwhosubmit.IndexOf("btnaddnew", StringComparison.OrdinalIgnoreCase) >= 0 && (!string.IsNullOrEmpty(_strMenuName))))
            {
                MenuModel _MenuModel = new MenuModel();
                _MenuModel.InsertMenu((MenuModel.MenuClassEnum)Enum.Parse(typeof(MenuModel.MenuClassEnum), _strMenuClass, true), new List <MenuViewModel>()
                {
                    new MenuViewModel()
                    {
                        MenuClass = _strMenuClass, MenuName = _strMenuName
                    }
                });
                _strMenuName = "";
            }
            //修改
            if (_strwhosubmit.IndexOf("btnSave", StringComparison.OrdinalIgnoreCase) >= 0 && (!string.IsNullOrEmpty(_strMenuName)) && (!string.IsNullOrEmpty(_MenuNo)))
            {
                MenuModel.UpdateMenu((MenuModel.MenuClassEnum)Enum.Parse(typeof(MenuModel.MenuClassEnum), _strMenuClass, true), _MenuNo, _strMenuName);
                _strMenuName = "";
            }
            //刪除
            if (_strwhosubmit.IndexOf("btndel", StringComparison.OrdinalIgnoreCase) >= 0 && (!string.IsNullOrEmpty(_MenuNo)))
            {
                MenuModel.DeleteMenu((MenuModel.MenuClassEnum)Enum.Parse(typeof(MenuModel.MenuClassEnum), _strMenuClass, true), new List <MenuViewModel>()
                {
                    new MenuViewModel()
                    {
                        MenuID = int.Parse(_MenuNo)
                    }
                });
            }


            return(RedirectToAction("Index", new { MenuClass = _strMenuClass, name = _strMenuName }));
        }