Esempio n. 1
0
        public async Task <string> CreateMenu(CreateMenuInput input)
        {
            input.CheckDataAnnotations().CheckValidResult();
            var exsitMenu = await _menuRepository.SingleOrDefaultAsync(p => p.Code == input.Code);

            if (exsitMenu != null)
            {
                throw new BusinessException($"系统中已经存在Code为{input.Code}的菜单信息");
            }
            var exsitPermission = await _permissionRepository.SingleOrDefaultAsync(p => p.Code == input.Code);

            if (exsitPermission != null)
            {
                throw new BusinessException($"系统中已经存在Code为{input.Code}的权限信息");
            }
            var menu       = input.MapTo <Menu>();
            var permission = new Permission()
            {
                Code = input.Code,
                Name = input.Name,
                Memo = input.Memo,
                Mold = PermissionMold.Menu
            };
            await _menuManager.CreateMenu(menu, permission);

            return("新增菜单成功");
        }
Esempio n. 2
0
 public override object GetUIObject(IToolBarItemContext context, IInputElement commandTarget)
 {
     if (menu == null)
     {
         menu = menuManager.CreateMenu(new Guid(MenuConstants.APP_MENU_GUID), commandTarget);
     }
     return(menu);
 }
Esempio n. 3
0
        public IActionResult CreateMenu([FromBody] MenuItem menuItem)
        {
            try
            {
                var stopwatch = StopwatchLogger.Start(_log);
                _log.Info("Called MenuController CreateMenu");

                if (menuItem != null && menuItem.ReferenceEntityId != null)
                {
                    if (menuItem.MenuTypeId == 1)
                    {
                        menuItem.ReferenceEntityId = _iMetadataManager.GetEntityContextByEntityName(menuItem.ReferenceEntityId, false);
                    }
                    else if (menuItem.MenuTypeId == 2)
                    {
                        menuItem.ReferenceEntityId = _iMetadataManager.GetEntityContextByEntityName(menuItem.ReferenceEntityId, true);
                    }
                }

                using (TransactionScope ts = new TransactionScope()) {
                    //create menu
                    var retVal = _iMenuManager.CreateMenu(menuItem, UserId, TenantCode);
                    _iMenuManager.ClearMenuCache(TenantCode);

                    //create resource
                    //get language key value
                    string langKey   = "";
                    string langValue = "";
                    var    retLan    = _resourceManager.GetDefaultLanguageByTenant(TenantCode);
                    if (retLan != null && retLan.Key != null)
                    {
                        langKey = Convert.ToString(retLan.Key);
                    }
                    if (retLan != null && retLan.Text != null)
                    {
                        langValue = Convert.ToString(retLan.Text);
                    }

                    //check resource by key
                    var retRes = _resourceManager.GetResourcesByKey(TenantCode, menuItem.Menucode);
                    if (retRes.Count == 0)
                    {
                        string msg = "";
                        _resourceManager.Create(TenantCode, new Entities.EntityCore.Model.Resource.Resource(menuItem.Menucode, menuItem.Name, langKey, langValue, menuItem.ReferenceEntityId, false), UserId, ref msg);
                    }

                    ts.Complete();

                    stopwatch.StopAndLog("CreateMenu method of MenuController");
                    return(Ok(retVal));
                }
            }
            catch (Exception ex)
            {
                _log.Error(ExceptionFormatter.SerializeToString(ex));
                return(StatusCode((int)HttpStatusCode.InternalServerError, ApiConstant.CustomErrorMessage));
            }
        }
Esempio n. 4
0
        public IActionResult Create(MenuCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                Menu menu = new Menu
                {
                    Naam    = model.Name,
                    OwnerID = User.FindFirstValue(ClaimTypes.NameIdentifier)
                };
                _menuManager.CreateMenu(menu);

                return(RedirectToAction(nameof(Edit), new { id = menu.ID }));
            }
            return(View(model));
        }