Esempio n. 1
0
        public async Task <BaseResponse> UpdateDataDefineAsync(DataDefineLibraryUpdateDto req, string account)
        {
            var data = await _dlr.FindAsync(req.Id);

            if (data == null)
            {
                return(new BaseResponse {
                    Success = false, Message = "输入的编号不存在"
                });
            }
            //验证是否重名
            var ret = await _dlr.Find(a => a.DataName == req.DataName && a.Id != req.Id).FirstOrDefaultAsync();

            if (ret != null)
            {
                return(new BaseResponse {
                    Success = false, Message = "已存在相同名称的数据定义"
                });
            }
            var entity = _mapper.Map(req, data);

            try
            {
                entity.Modify     = account;
                entity.ModifyTime = DateTime.Now;
                await _dlr.SaveAsync(data);

                _log.LogInformation($"{account}修改Id为{req.Id}数据定义库成功");
                return(new BaseResponse {
                    Success = true, Message = "修改数据成功"
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}修改Id为{req.Id}的数据定义库失败,失败原因{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "修改数据失败,请联系管理员"
                });
            }
        }
Esempio n. 2
0
 //调用者检查类型是否存在
 public async Task<BaseResponse> AddTypeDataDefine(int typeId, TypeDataDefineAddViewModel req, string account)
 {
     //验证类型是否可以添加
     var t = await _tr.FindAsync(typeId);
     if (t.Status == TypeStatus.Root)
     {
         return new BaseResponse { Success = false, Message = "目录节点类型不能添加具体数据" };
     }
     var dataDefine = await _ddl.FindAsync(req.DataDefineId);
     if (dataDefine == null)
     {
         return new BaseResponse { Success = false, Message = "输入的数据类型定义标示不存在" };
     }
     //检查是否已存在相同key值
     var ret = await _td.Find(a => a.TypeId == typeId && a.DataKey == dataDefine.DataKey).FirstOrDefaultAsync();
     if (ret != null)
     {
         return new BaseResponse { Success = false, Message = "该类型下存在相同key值" };
     }
     try
     {
         var entity = _mapper.Map<TypeDataDefineModel>(req);
         entity.Create = account;
         entity.TypeId = typeId;
         entity.DataKey = dataDefine.DataKey;
         entity.DataName = dataDefine.DataName;
         entity.Unit = dataDefine.Unit;
         entity.DataType = dataDefine.DataType;
         entity.DefaultValue = dataDefine.DefaultValue;
         entity.Format = dataDefine.Format;
         entity.Model = (DataDefineModel)dataDefine.Model;
         entity.Category = dataDefine.Category;
         await _td.AddAsync(entity);
         _log.LogInformation($"{account}添加类型数据定义{entity.DataKey}成功");
         return new HandleResponse<int> { Success = true, Message = "添加数据成功", Key = entity.Id };
     }
     catch (Exception ex)
     {
         _log.LogError($"{account}添加类型数据定义{dataDefine.DataKey}失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
         return new BaseResponse { Success = false, Message = "添加数据失败,请联系管理员" };
     }
 }