Beispiel #1
0
        /// <summary>
        /// 添加(批量添加)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Creat(MenuButtonModel model)
        {
            try
            {
                var menuId    = Guid.Parse(model.MenuIds);
                var buttonIds = model.ButtonIds.Split(',');
                var menu      = menuDal.Find(menuId);
                if (menu == null)
                {
                    throw new Exception("无法识别菜单ID");
                }
                else
                {
                    var isScussce = dal.DelByMenuId(menuId);
                    if (!isScussce)
                    {
                        throw new Exception("出现程序错误,请联系管理员!");
                    }
                }
                foreach (var bid in buttonIds)
                {
                    var buttonId = Guid.Parse(bid);
                    if (buttonId != Guid.Empty)
                    {
                        var menuButton = new MenuButton
                        {
                            Id       = Guid.NewGuid(),
                            MenuId   = menuId,
                            ButtonId = buttonId
                        };
                        var result = dal.Create(menuButton);
                        if (result == null)
                        {
                            throw new Exception("循环添加出现程序错误,请联系管理员!");
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception("出现程序错误,请联系管理员!");
            }
        }