diff --git a/YD_AllHeartRates.Api/Services/Impl/DeviceService.cs b/YD_AllHeartRates.Api/Services/Impl/DeviceService.cs
index 2229abf..a3317fb 100644
--- a/YD_AllHeartRates.Api/Services/Impl/DeviceService.cs
+++ b/YD_AllHeartRates.Api/Services/Impl/DeviceService.cs
@@ -143,10 +143,13 @@ namespace YD_AllHeartRates.Api.Services.Impl
///
public async Task AddDevice([FromBody] AddDeviceDto dto)
{
- var student = await _sportsContext.Student.Where(x => x.StudentNo == dto.StudentNo).FirstOrDefaultAsync();
+ if (!string.IsNullOrWhiteSpace(dto.StudentNo))
+ {
+ 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();
@@ -180,10 +183,13 @@ namespace YD_AllHeartRates.Api.Services.Impl
if (device == null)
throw new Exception("更新的设备不存在");
- var student = await _sportsContext.Student.Where(x => x.StudentNo == dto.StudentNo).FirstOrDefaultAsync();
+ if (!string.IsNullOrWhiteSpace(dto.StudentNo))
+ {
+ 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;