Exemplo n.º 1
0
        public async Task <ActionResult <BaseResponse> > Add(int typeId, [FromBody] TypeSchemaAddViewModel 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 _tss.AddSchemaAsync(typeId, req, Account);

            return(rm);
        }
Exemplo n.º 2
0
        public async Task <BaseResponse> AddSchemaAsync(int typeId, TypeSchemaAddViewModel req, string account)
        {
            //验证类型是否可以添加
            var t = await _tr.FindAsync(typeId);

            if (t.Status == TypeStatus.Root)
            {
                return(new BaseResponse {
                    Success = false, Message = "目录节点类型不能添加具体数据"
                });
            }
            //检查是否存在同名
            var data = await _ts.Find(a => a.TypeId == typeId && a.ParentId == req.ParentId && a.Name == req.Name).FirstOrDefaultAsync();

            if (data != null)
            {
                return(new BaseResponse {
                    Success = false, Message = "已存在相同名称的模式"
                });
            }
            var define = await _td.FindAsync(req.DataDefineId);

            //检查所对应的key值是否存在
            if (define == null)
            {
                return(new BaseResponse {
                    Success = false, Message = "输入的数据定义不存在"
                });
            }
            try
            {
                if (req.ParentId == 0)
                {
                    req.ParentId = null;
                }
                var entity = _mapper.Map <TypeSchemaModel>(req);
                entity.Create = account;
                entity.TypeId = typeId;
                entity.Key    = define.DataKey;
                await _ts.AddAsync(entity);

                _log.LogInformation($"{account}添加模式成功,模式标示为{entity.Id}");
                return(new HandleResponse <int> {
                    Success = true, Message = "添加模式成功", Key = entity.Id
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}添加模式失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "添加模式失败,请联系管理员"
                });
            }
        }