public async Task <BaseResponse> AddAccessoryControlData(int accessoryId, TypeControlDataAddDto req, string account) { var data = await _tacr.Find(a => a.AccessoryId == accessoryId && a.ControlName == req.ControlName).FirstOrDefaultAsync(); if (data != null) { return(new BaseResponse { Success = false, Message = "已存在相同名称的控制数据" }); } try { var entity = _mapper.Map <TypeAccessoryControlDataModel>(req); entity.Create = account; entity.AccessoryId = accessoryId; await _tacr.AddAsync(entity); _log.LogInformation($"{account}创建类型配件控制数据成功"); 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 = "创建类型配件控制数据失败,请联系管理员" }); } }
public async Task <ActionResult <BaseResponse> > AddAsync(int accessoryId, TypeControlDataAddDto req) { //string user = User.Identity.Name; //if (string.IsNullOrWhiteSpace(user)) //{ // return Unauthorized("用户凭证缺失"); //} //UserMessage um = JsonConvert.DeserializeObject<UserMessage>(user); //string GroupId; //var ret = _tas.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("用户没有权限"); //} //验证数据定义标示是否存在 var data = await _tds.IsExist(a => a.Id == req.DataDefineId); if (!data) { return(new BaseResponse { Success = false, Message = "输入的数据定义标示不存在" }); } //验证关联的数据定义是否存在 if (req.AssociateDefineId != 0) { data = await _tds.IsExist(a => a.Id == req.AssociateDefineId); if (!data) { return(new BaseResponse { Success = false, Message = "输入的关联数据定义标示不存在" }); } } string Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value; var rm = await _tacs.AddAccessoryControlData(accessoryId, req, Account); return(rm); }