Пример #1
0
        public int Delete(string token, string id)
        {
            BuildingScript oldBuildingScript = Get(token, id);

            if (oldBuildingScript?.userId != _SessionMgeSvr.Get(token).Name)
            {
                throw new ServiceException((int)TYPE_OF_RESULT_TYPE.failure, "无权限");
            }
            File.Delete($"{_ScriptsPath}/{oldBuildingScript.id}.js");
            return(_BuildingScriptDao.Delete(oldBuildingScript));
        }
Пример #2
0
        public BuildingScript Update(string token, string id, BuildingScript buildingScript)
        {
            BuildingScript oldBuildingScript = Get(token, id);

            if (oldBuildingScript?.userId != _SessionMgeSvr.Get(token).Name)
            {
                throw new ServiceException((int)TYPE_OF_RESULT_TYPE.failure, "无权限");
            }
            buildingScript.createTime = oldBuildingScript.createTime;
            buildingScript.id         = oldBuildingScript.id;
            buildingScript.userId     = oldBuildingScript.userId;
            SaveJsFile(buildingScript);
            _BuildingScriptDao.Update(buildingScript);
            return(buildingScript);
        }
Пример #3
0
        public BuildingScript Create(string token, BuildingScript buildingScript)
        {
            buildingScript.id         = Guid.NewGuid().ToString();
            buildingScript.createTime = DateTime.Now;
            buildingScript.userId     = _SessionMgeSvr.Get(token).Name;
            _BuildingScriptDao.Insert(buildingScript);
            SaveJsFile(buildingScript);
            FavoriteScript script = new FavoriteScript();

            script.id       = Guid.NewGuid().ToString();
            script.addTime  = DateTime.Now;
            script.scriptId = buildingScript.id;
            script.userId   = _SessionMgeSvr.Get(token).Name;
            _FavoriteScriptDao.Insert(script);
            return(buildingScript);
        }
Пример #4
0
        public BuildingScript Get(string token, string id)
        {
            BuildingScript buildingScript = new BuildingScript {
                id = id
            };

            buildingScript = _BuildingScriptDao.Get(buildingScript) as BuildingScript;
            if (buildingScript == null)
            {
                throw new ServiceException((int)TYPE_OF_RESULT_TYPE.failure, "指定id不存在");
            }
            if (!(buildingScript.state == (int)TYPE_BUILDINGSCRIPT_STATE.PUBLIC || buildingScript?.userId == _SessionMgeSvr.Get(token).Name))
            {
                throw new ServiceException((int)TYPE_OF_RESULT_TYPE.failure, "无权限");
            }
            string content = File.ReadAllText($"{_ScriptsPath}/{buildingScript.id}.js");

            buildingScript.content = content.Split("//---")[0];
            return(buildingScript);
        }