コード例 #1
0
        private bool Validate(AppImportSettingsViewModel model, List <FunctionNode> functionNodeList, out ActionResult result)
        {
            result = new ActionResult();
            //app
            string newAppCode = model.AppCode.Trim();
            string oldAppCode = app.AppCode;

            if (string.IsNullOrEmpty(newAppCode))
            {
                result.Success = false;
                result.Message = "Apps.Msg3";
                return(false);
            }
            if (this.Engine.AppNavigationManager.GetApp(newAppCode) != null && model.IsCover == false)
            {
                result.Success = false;
                result.Message = "Apps.Msg4";
                return(false);
            }
            app.AppCode     = newAppCode;
            app.DisplayName = model.AppName.Trim();
            //更新app一级菜单的ParentCode
            functionNodeList.FindAll(i => i.ParentCode == oldAppCode).ForEach(i => i.ParentCode = newAppCode);

            FunctionNode[] levelOneNodes = this.Engine.FunctionAclManager.GetFunctionNodesByParentCode(newAppCode);
            //菜单
            if (model.FunctionNodeList.Count == functionNodeList.Count)
            {
                for (int j = 0; j < functionNodeList.Count; j++)
                {
                    string oldCode = functionNodeList[j].Code;
                    string newCode = model.FunctionNodeList[j].Code;
                    string newName = model.FunctionNodeList[j].DisplayName;
                    if (string.IsNullOrEmpty(newCode))
                    {
                        result.Success = false;
                        result.Message = "Apps.Msg5";
                        return(false);
                    }
                    FunctionNode oldNode = this.Engine.FunctionAclManager.GetFunctionNodeByCode(newCode);
                    //菜单存在,且不属于当前app或者app的一级菜单
                    if (oldNode != null && !(oldNode.ParentCode == newAppCode ||
                                             (levelOneNodes != null && levelOneNodes.Count(i => oldNode.ParentCode == i.Code) > 0)))
                    {
                        result.Success = false;
                        result.Message = "Apps.Msg6";
                        return(false);
                    }
                    FunctionNode node = functionNodeList.First(i => i.Code == oldCode);
                    node.ObjectID    = Guid.NewGuid().ToString();
                    node.Serialized  = false;
                    node.Code        = newCode;
                    node.DisplayName = newName;
                    //更新当前菜单的下级菜单的ParentCode
                    functionNodeList.FindAll(i => i.ParentCode == oldCode).ForEach(i => i.ParentCode = newCode);
                }
            }
            return(true);
        }
コード例 #2
0
        public JsonResult ImportApp(string appImportSettingsStr)
        {
            return(ExecuteFunctionRun(() =>
            {
                AppImportSettingsViewModel model = JsonConvert.DeserializeObject <AppImportSettingsViewModel>(appImportSettingsStr);
                ActionResult result = new ActionResult();
                string xmlStr = Session[model.FileName] == null ? "" : Session[model.FileName].ToString();
                List <FunctionNode> oldFunctionList = null;
                if (!ReadXmlFile(xmlStr, out oldFunctionList))
                {
                    result.Success = false;
                }
                if (!Validate(model, oldFunctionList, out result))
                {
                    return Json(result, JsonRequestBehavior.AllowGet);
                }

                try
                {
                    AppNavigation oldApp = this.Engine.AppNavigationManager.GetApp(app.AppCode);
                    if (oldApp == null)
                    {
                        app.ObjectID = Guid.NewGuid().ToString();
                        app.Serialized = false;
                        this.Engine.AppNavigationManager.AddApp(app);
                    }
                    else
                    {
                        if (model.IsCover)
                        {
                            app.ObjectID = oldApp.ObjectID;
                            this.Engine.AppNavigationManager.UpdateApp(app);
                        }
                    }
                    //先删除菜单
                    FunctionNode[] oldNodes = this.Engine.FunctionAclManager.GetFunctionNodesByParentCode(app.AppCode);
                    if (oldNodes != null)
                    {
                        foreach (FunctionNode oldNode in oldNodes)
                        {
                            this.Engine.FunctionAclManager.RemoveFunctionNodeByCode(oldNode.Code, true);
                        }
                    }
                    //添加菜单
                    foreach (FunctionNode node in oldFunctionList)
                    {
                        this.Engine.FunctionAclManager.AddFunctionNode(node);
                    }
                    //从缓存中移除文件内容

                    Session.Remove(model.FileName);
                    result.Success = true;
                }
                catch (Exception ex)
                {
                    result.Success = false;
                    result.Message = "Apps.ImportFail";
                    result.Extend = ex.Message;
                }

                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }