Beispiel #1
0
        /// <summary>
        /// 删除控件信息
        /// </summary>
        /// <param name="id">主键id</param>
        /// <param name="sc">上下文服务对象</param>
        /// <returns>成功返回true;否则返回false</returns>
        public bool Delete(String id, IServerContext sc)
        {
            Func <bool> func = () =>
            {
                //          只能删除未发布过的
                IControlDAL   dal  = GetDAL <IControlDAL>(sc);
                ControlEntity data = dal.LoadData(id, sc);
                if (data == null)
                {
                    ThrowErrorCodeException("不存在此控件");
                }
                //          删除
                return(dal.DeleteData(id, sc));
            };

            return(this.CallFunc <bool>(func, sc, "Delete", "删除控件信息"));
        }
Beispiel #2
0
        /// <summary>
        /// 保存控件信息
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="sc"></param>
        /// <returns></returns>
        public ControlEntity Save(ControlEntity entity, IServerContext sc)
        {
            Func <ControlEntity> func = () =>
            {
                //          1.1 数据验证
                if (entity == null)
                {
                    ThrowErrorCodeException("数据对象为空");
                }
                if (String.IsNullOrEmpty(entity.Code))
                {
                    ThrowArgException("控件编码不能为空");
                }
                if (String.IsNullOrEmpty(entity.Name))
                {
                    ThrowArgException("控件名称不能为空");
                }
                if (String.IsNullOrEmpty(entity.Id))
                {
                    entity.Id = Guid.NewGuid().ToString();
                }
                ServerContextInfo scInfo = GetServerContextInfo(sc);
                //          1.2 默认值处理
                #region 代码折叠:       默认值处理
                String        id      = entity.Id;
                IControlDAL   dal     = this.GetDAL <IControlDAL>(sc);
                ControlEntity oldData = dal.LoadData(id, sc);

                if (oldData == null)
                {
                    //              新增数据
                    entity.AddTime        = DateTime.Now;
                    entity.AddUserId      = scInfo.UserId;
                    entity.OrganizationId = scInfo.OrgId;
                }
                #endregion
                //          1.3 保存数据
                entity = dal.SaveData(entity, sc);
                return(entity);
            };

            return(this.CallFunc <ControlEntity>(func, sc, "Save", "保存控件数据"));
        }