public async Task <BaseResponse> AddDeviceCardAsync(string DeviceSn, DeviceCardAddDto req, string account) { //检查该设备是否已存在流量卡 var d = await _dcr.Find(a => a.DeviceSn == DeviceSn).CountAsync(); if (d > 0) { return(new BaseResponse { Success = false, Message = "该设备已存在流量卡数据" }); } if (req.CardNo != null && "" != req.CardNo) { var card = await _dcr.Find(a => a.CardNo == req.CardNo).CountAsync(); if (card > 0) { return(new BaseResponse { Success = false, Message = "输入的卡号被占用" }); } } try { var entity = _mapper.Map <DeviceCardModel>(req); entity.DeviceSn = DeviceSn; entity.Create = account; await _dcr.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 = "添加流量卡失败,请联系管理员" }); } }
public async Task <ActionResult <BaseResponse> > AddDeviceCard(string GroupId, string DeviceSn, [FromBody] DeviceCardAddDto req) { var account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value; //添加流量卡 var rm = await _dcs.AddDeviceCardAsync(DeviceSn, req, account); return(rm); }