Exemplo n.º 1
0
        /// <summary>
        /// 【设计时】保存设计时数据
        /// </summary>
        /// <param name="data">要保存的数据</param>
        /// <param name="fromPublishModel">调用此接口的来源动作:是否来自发布模块</param>
        /// <param name="sc">上下文服务</param>
        /// <returns>保存成功配置对象,否则返回null</returns>
        public ModelDesignData SaveDesignData(ModelDesignData data, Boolean fromPublishModel, IServerContext sc)
        {
            Func <ModelDesignData> func = () =>
            {
                //          1.1 数据验证
                if (data == null)
                {
                    ThrowErrorCodeException("数据对象为空");
                }
                if (String.IsNullOrEmpty(data.Name))
                {
                    ThrowArgException("请输入模块名称");
                }
                if (String.IsNullOrEmpty(data.Id))
                {
                    data.Id = Guid.NewGuid().ToString();
                }
                ServerContextInfo scInfo = GetServerContextInfo(sc);
                //          1.2 默认值处理
                #region 代码折叠:       默认值处理
                String id = data.Id;
                IModelDesignDataDAL dal     = this.GetDAL <IModelDesignDataDAL>(sc);
                ModelDesignData     oldData = dal.LoadData(id, sc);
                if (oldData == null)
                {
                    //              新增数据
                    data.AddTime   = DateTime.Now;
                    data.AddUserId = scInfo.UserId;
                }
                //                  模块状态处理:是【发布模块】调用此接口时始终为【已发布】;否则新增时为【始终未发布】,保存时为【已保存未发布】
                if (fromPublishModel == true)
                {
                    data.State         = ModelState.Published;
                    data.PublishTime   = DateTime.Now;
                    data.PublishUserId = scInfo.UserId;
                }
                else
                {
                    if (oldData == null || oldData.State == ModelState.Never)
                    {
                        data.State = ModelState.Never;
                    }
                    else
                    {
                        data.State = ModelState.Saved;
                    }
                }
                #endregion
                //          1.3 保存数据
                data = dal.SaveData(data, sc);
                //          1.4 记录保存日志
                this.WriteLog("保存模块数据", oldData, data, sc);
                //          1.5 返回数据
                return(data);
            };

            return(this.CallFunc <ModelDesignData>(func, sc, "SaveDesignData", "【设计时】保存设计时数据"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 【设计时】删除设计时数据
        /// </summary>
        /// <param name="id">主键id</param>
        /// <param name="sc">上下文服务对象</param>
        /// <returns>成功返回true;否则返回false</returns>
        public Boolean DeleteDesignData(String id, IServerContext sc)
        {
            Func <Boolean> func = () =>
            {
                //          只能删除未发布过的
                IModelDesignDataDAL dal  = GetDAL <IModelDesignDataDAL>(sc);
                ModelDesignData     data = dal.LoadData(id, sc);
                if (data == null)
                {
                    ThrowErrorCodeException("不存在此模块");
                }
                if (data.State != ModelState.Never)
                {
                    ThrowErrorCodeException("只能删除从未发布过的模块");
                }
                //          删除
                return(dal.DeleteData(id, sc));
            };

            return(this.CallFunc <Boolean>(func, sc, "DeleteDesignData", "【设计时】删除设计时数据"));
        }