示例#1
0
        public async Task <BaseResponse> AddTypeModuleControlAsync(string Account /*, int ModuleId*/, TypeModuleControlAddDto req)
        {
            //2021-3-1 名称可以重复,key不能重复(数据定义不能重复)
            var count = await _tmcr.Find(a => a.ModuleId == req.ModuleId && a.DataDefineId == req.DataDefineId).CountAsync();

            if (count > 0)
            {
                return(new BaseResponse {
                    Success = false, Message = "此模块下已添加相同的控制项"
                });
            }
            try
            {
                var entity = _map.Map <TypeModuleControlModel>(req);
                entity.Create = Account;
                //entity.ModuleId = reqModuleId;
                await _tmcr.AddAsync(entity);

                _log.LogInformation($"{Account}添加标示为{entity.Id}的控制项成功");
                return(new HandleResponse <int> {
                    Success = true, Message = "添加数据成功", Key = entity.Id
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{Account}添加模块标示为{req.ModuleId}的控制项失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "添加数据失败,请联系管理员"
                });
            }
        }
示例#2
0
        public async Task <ActionResult <BaseResponse> > AddTypeModuleControlAsync(int typeId, [FromBody] TypeModuleControlAddDto req)
        {
            string Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value;

            #region 检测类型
            var type = await _ts.CheckTypeAsync(typeId);

            if (!type.IsExist)
            {
                return(new BaseResponse {
                    Success = false, Message = "输入的类型编号不存在"
                });
            }
            if (type.Status == 0)
            {
                return(new BaseResponse {
                    Success = false, Message = "该类型为目录型节点,不允许添加数据"
                });
            }
            #endregion
            #region 检测数据定义标示是否存在
            var td = await _td.IsExist(a => a.Id == req.DataDefineId);

            if (!td)
            {
                return(new BaseResponse {
                    Success = false, Message = "输入的类型数据定义不存在"
                });
            }
            #endregion
            #region 检查模块是否存在
            var exist = await _tms.IsExist(a => a.Id == req.ModuleId && a.TypeId == typeId);

            if (!exist)
            {
                return(new BaseResponse {
                    Success = false, Message = "输入的类型模块在该类型下不存在"
                });
            }
            #endregion
            var rm = await _tmcs.AddTypeModuleControlAsync(Account, req);

            return(rm);
        }