diff --git a/YD_AllHeartRates.Api/Services/Impl/DeviceService.cs b/YD_AllHeartRates.Api/Services/Impl/DeviceService.cs index cdb385d..2229abf 100644 --- a/YD_AllHeartRates.Api/Services/Impl/DeviceService.cs +++ b/YD_AllHeartRates.Api/Services/Impl/DeviceService.cs @@ -145,8 +145,14 @@ namespace YD_AllHeartRates.Api.Services.Impl { var student = await _sportsContext.Student.Where(x => x.StudentNo == dto.StudentNo).FirstOrDefaultAsync(); - if (student == null) - throw new Exception($"学号:{dto.StudentNo}的学生不存在!"); + if (student != null) + throw new Exception($"学号:{dto.StudentNo}的学生已存在!"); + + var device = await _sportsContext.Device.Where(x => x.Code == dto.Code).FirstOrDefaultAsync(); + + if (device != null) + throw new Exception($"设备编号:{dto.Code}的学生已存在!"); + var entity = new S_Device() { @@ -176,8 +182,8 @@ namespace YD_AllHeartRates.Api.Services.Impl var student = await _sportsContext.Student.Where(x => x.StudentNo == dto.StudentNo).FirstOrDefaultAsync(); - if (student == null) - throw new Exception($"学号:{dto.StudentNo}的学生不存在!"); + if (student != null) + throw new Exception($"学号:{dto.StudentNo}的学生已存在!"); device.StudentNo = dto.StudentNo; device.DeviceType = dto.DeviceType;