From 580d586b2d20254267b1182a8ceff393c252da81 Mon Sep 17 00:00:00 2001
From: tanglong <842690096@qq.com>
Date: Wed, 2 Jul 2025 14:19:46 +0800
Subject: [PATCH] d
---
.../Services/Impl/DeviceService.cs | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
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;