コード例 #1
0
ファイル: TypeDataDefineService.cs プロジェクト: qkxyk/hxcore
 //调用者检查类型是否存在
 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 = "添加数据失败,请联系管理员" };
     }
 }
コード例 #2
0
        public async Task <ActionResult <BaseResponse> > AddTypeDataDefine(int typeId, TypeDataDefineAddViewModel req)
        {
            //string user = User.Identity.Name;
            //if (string.IsNullOrWhiteSpace(user))
            //{
            //    return Unauthorized("用户凭证缺失");
            //}
            //UserMessage um = JsonConvert.DeserializeObject<UserMessage>(user);
            //string GroupId;
            //int status;
            //var ret = _ts.IsExist(typeId, out GroupId, out status);
            //if (!ret)
            //{
            //    return new BaseResponse { Success = false, Message = "输入的类型不存在" };
            //}
            //if (status == 0)
            //{
            //    return new BaseResponse { Success = false, Message = "目录节点类型不能添加具体数据" };
            //}
            //if (!(um.IsAdmin && (um.GroupId == GroupId || um.Code == _config["Group"])))
            //{
            //    return Unauthorized("用户没有权限");
            //}
            string Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value;
            var    rm      = await _td.AddTypeDataDefine(typeId, req, Account);

            return(rm);
        }