Esempio n. 1
0
        public CommandResult <LeftMenus> Add(LeftMenusAddRequestModel requestModel)
        {
            var result = new CommandResult <LeftMenus>();

            using (var db = new FrameContext())
            {
                if (requestModel.MenuId != null && requestModel.MenuId.Trim().Length != 0 && BaseService.Exist(db, a => a.MenuId == requestModel.MenuId))
                {
                    result.Message = $"菜单唯一标识“{requestModel.MenuId}”,在系统中已存在,请重新输入……";
                }
                else
                {
                    var entity = new LeftMenus
                    {
                        DisplayName   = requestModel.DisplayName,
                        DllPath       = requestModel.DllPath,
                        EntryFunction = requestModel.EntryFunction,
                        MenuId        = requestModel.MenuId,
                        NavBarGroupId = requestModel.NavBarGroupId,
                        ParentId      = requestModel.ParentId,
                        Sort          = requestModel.Sort,
                        StartWithSys  = requestModel.StartWithSys,
                        Timestamp     = requestModel.Timestamp
                    };
                    if (!BaseService.Add(db, entity))
                    {
                        result.Message = "未知原因";
                    }
                    else
                    {
                        result.ResultStatus = ResultStatus.Success;
                        result.Message      = "新的节点信息添加成功";
                        result.Data         = entity;
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
        {
            if (!_clsLoginModel.PermissionsFunc(_currentMenuId, (int)PermissionsEnum.添加))
            {
                _metroWindow.ShowMessageAsync("友情提示", "您没有添加菜单信息的权限");
                return;
            }
            if (!Verify())
            {
                return;
            }
            if (!JudgeDisplayNameNotRootName(_metroWindow, DisplayName))
            {
                return;
            }

            Action addAction = () =>
            {
                var requestModel = new LeftMenusAddRequestModel
                {
                    DisplayName   = DisplayName,
                    DllPath       = DllPath,
                    EntryFunction = EntryFunction,
                    MenuId        = MenuId,
                    NavBarGroupId = NavBarGroupId,
                    ParentId      = ParentId,
                    Sort          = int.MaxValue,
                    StartWithSys  = StartWithSysYes,
                    Timestamp     = _leftMenusManage.ServerTime.ToUnixTimestamp()
                };
                var result = _leftMenusManage.Add(requestModel);
                if (result.ResultStatus == ResultStatus.Success)
                {
                    ClearMenuData();
                    AddTreeViewItem(result.Data);
                    _leftMenu.LeftMenusList = _leftMenusManage.GetAll().ToList();
                }
                _metroWindow.ShowMessageAsync(result.ResultStatus == ResultStatus.Success ? "添加成功提示" : "添加失败提示", result.Message);
            };


            var setting = new MetroDialogSettings
            {
                AnimateShow           = true,
                AnimateHide           = true,
                AffirmativeButtonText = "是",
                NegativeButtonText    = "否",
                DefaultButtonFocus    = MessageDialogResult.Negative
            };

            if (_leftMenusManage.Exist(a => a.DisplayName == DisplayName.Trim()))
            {
                _metroWindow.ShowMessageAsync("信息重复提示", $"菜单名称“{DisplayName}”,在系统中已存在,是否仍使用该名称?", MessageDialogStyle.AffirmativeAndNegative, setting).ContinueWith(
                    t =>
                {
                    _metroWindow.Dispatcher.Invoke((Action)(() =>
                    {
                        if (t.Result == MessageDialogResult.Affirmative)
                        {
                            addAction();
                        }
                    }));
                });
            }
            else
            {
                addAction();
            }
        }