コード例 #1
0
        public async Task <BaseResponse> AddSystemControlDataAsync(int accessoryId, TypeSystemAccessoryControlDataAddDto req, string account)
        {
            var data = await _tscr.Find(a => a.AccessoryId == accessoryId && a.ControlName == req.ControlName).FirstOrDefaultAsync();

            if (data != null)
            {
                return(new BaseResponse {
                    Success = false, Message = "该配件下已存在相同名称的控制数据"
                });
            }
            try
            {
                var entity = _mapper.Map <TypeSystemAccessoryControlDataModel>(req);
                entity.AccessoryId = accessoryId;
                entity.Create      = account;
                await _tscr.AddAsync(entity);

                _log.LogInformation($"{account}添加标示为{entity.Id}的类型配件控制数据成功");
                return(new HandleResponse <int> {
                    Success = true, Message = "添加控制数据成功"
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}添加类型配件控制数据失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "添加类型配件控制数据失败"
                });
            }
        }
コード例 #2
0
        public async Task <ActionResult <BaseResponse> > AddSystemControlDataAsync(int accessoryId, TypeSystemAccessoryControlDataAddDto req)
        {
            bool IsExist = await _tds.IsExist(a => a.Id == req.DataDefineId);

            if (!IsExist)
            {
                return(new BaseResponse {
                    Success = false, Message = "输入的类型数据定义不存在"
                });
            }
            if (req.AssociateDefineId != 0)
            {
                IsExist = await _tds.IsExist(a => a.Id == req.AssociateDefineId);

                if (!IsExist)
                {
                    return(new BaseResponse {
                        Success = false, Message = "输入的关联类型数据定义不存在"
                    });
                }
            }
            //string user = User.Identity.Name;
            //if (string.IsNullOrWhiteSpace(user))
            //{
            //    return Unauthorized("用户凭证缺失");
            //}
            //UserMessage um = JsonConvert.DeserializeObject<UserMessage>(user);
            //string GroupId;
            //var ret = _tsas.IsExist(a => a.Id == accessoryId, out GroupId);
            //if (!ret)
            //{
            //    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 _tscs.AddSystemControlDataAsync(accessoryId, req, Account);

            return(rm);
        }