This commit is contained in:
tanglong 2025-07-02 14:19:46 +08:00
parent db301ead3c
commit 580d586b2d

View File

@ -143,10 +143,13 @@ namespace YD_AllHeartRates.Api.Services.Impl
/// <returns></returns> /// <returns></returns>
public async Task<bool> AddDevice([FromBody] AddDeviceDto dto) public async Task<bool> 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) if (student != null)
throw new Exception($"学号:{dto.StudentNo}的学生已存在!"); throw new Exception($"学号:{dto.StudentNo}的学生已存在!");
}
var device = await _sportsContext.Device.Where(x => x.Code == dto.Code).FirstOrDefaultAsync(); 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) if (device == null)
throw new Exception("更新的设备不存在"); 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) if (student != null)
throw new Exception($"学号:{dto.StudentNo}的学生已存在!"); throw new Exception($"学号:{dto.StudentNo}的学生已存在!");
}
device.StudentNo = dto.StudentNo; device.StudentNo = dto.StudentNo;
device.DeviceType = dto.DeviceType; device.DeviceType = dto.DeviceType;