public async Task <ActionResult <BaseResponse> > AddWarnCode(int warnTypeId, WarnCodeAddDto req) { string Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value; var rm = await _wcs.AddWarnCodeAsync(Account, warnTypeId, req); return(rm); }
public async Task <BaseResponse> AddWarnCodeAsync(string account, int warnTypeId, WarnCodeAddDto req) { var code = await _warnCode.FindAsync(req.Code); if (code != null) { return(new BaseResponse { Success = false, Message = "已存在相同的代码" }); } try { var entity = _mapper.Map <WarnCodeModel>(req); entity.WarnTypeId = warnTypeId; entity.Create = account; await _warnCode.AddAsync(entity); _log.LogInformation($"{account}添加代码为{req.Code}的报警代码成功"); return(new HandleResponse <string> { Success = true, Message = "添加数据成功", Key = req.Code }); } catch (Exception ex) { _log.LogError($"{account}添加代码为{req.Code}的报警代码失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}"); return(new BaseResponse { Success = false, Message = "添加报警代码失败,请联系管理员" }); } }