コード例 #1
0
ファイル: TypeSystemController.cs プロジェクト: qkxyk/hxcore
        public async Task <ActionResult <BaseResponse> > AddTypeSystem(int typeId, TypeSystemAddDto 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.AddTypeSystemAsync(typeId, req, Account);

            return(rm);
        }
コード例 #2
0
ファイル: TypeSystemService.cs プロジェクト: qkxyk/hxcore
        public async Task <BaseResponse> AddTypeSystemAsync(int typeId, TypeSystemAddDto req, string account)
        {
            //验证类型是否可以添加
            var t = await _tr.FindAsync(typeId);

            if (t.Status == TypeStatus.Root)
            {
                return(new BaseResponse {
                    Success = false, Message = "目录节点类型不能添加具体数据"
                });
            }
            var data = await _tsr.Find(a => a.TypeId == typeId && a.Name == req.Name).FirstOrDefaultAsync();

            if (data != null)
            {
                return(new BaseResponse {
                    Success = false, Message = "该类型下存在相同名称的子系统"
                });
            }
            try
            {
                var entity = _mapper.Map <TypeSystemModel>(req);
                entity.Create = account;
                entity.TypeId = typeId;
                await _tsr.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 = "添加类型子系统失败,请联系管理员"
                });
            }
        }