From ca4f50d69bba8921fcde48f9805fda04cb9a5d39 Mon Sep 17 00:00:00 2001 From: tanglong <842690096@qq.com> Date: Tue, 1 Jul 2025 13:35:38 +0800 Subject: [PATCH] . --- YD_AllHeartRates.Api/Services/Impl/DeviceService.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/YD_AllHeartRates.Api/Services/Impl/DeviceService.cs b/YD_AllHeartRates.Api/Services/Impl/DeviceService.cs index d1c393a..cdb385d 100644 --- a/YD_AllHeartRates.Api/Services/Impl/DeviceService.cs +++ b/YD_AllHeartRates.Api/Services/Impl/DeviceService.cs @@ -143,6 +143,11 @@ 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 (student == null) + throw new Exception($"学号:{dto.StudentNo}的学生不存在!"); + var entity = new S_Device() { Code = dto.Code, @@ -169,6 +174,11 @@ 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 (student == null) + throw new Exception($"学号:{dto.StudentNo}的学生不存在!"); + device.StudentNo = dto.StudentNo; device.DeviceType = dto.DeviceType; device.Name = dto.DeviceType == 1 ? "心率" : "跳绳";