From 26c69c10b46d978253395c24f0e9f0a087e8cb90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A8=81=E5=8B=9D=20=E5=BC=B5?= Date: Wed, 22 May 2024 09:36:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=9D=E5=B0=8D=E6=88=90=E5=93=A1=E6=96=B0?= =?UTF-8?q?=E5=A2=9EAPI=E9=80=B2=E8=A1=8C=E8=BB=8A=E7=89=8C=E7=A2=BA?= =?UTF-8?q?=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Yuntech_parking_user_listController.cs | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/WebApi_data_value/Controllers/Yuntech_parking_user_listController.cs b/WebApi_data_value/Controllers/Yuntech_parking_user_listController.cs index fc55c2e..39f9e5e 100644 --- a/WebApi_data_value/Controllers/Yuntech_parking_user_listController.cs +++ b/WebApi_data_value/Controllers/Yuntech_parking_user_listController.cs @@ -120,24 +120,34 @@ namespace WebApi_data_value.Controllers { return Problem("Entity set 'SqlContext.yuntech_parking_user_list' is null."); } - _context.yuntech_parking_user_list.Add(yuntech_parking_user_list); - try + var license_plate_number = yuntech_parking_user_list.user_license_plate_number; + var data = await(from c in _context.yuntech_parking_user_list + where c.user_license_plate_number == license_plate_number + select c + ).FirstOrDefaultAsync(); + if (data == null) { - await _context.SaveChangesAsync(); - } - catch (DbUpdateException) - { - if (Yuntech_parking_user_listExists(yuntech_parking_user_list.user_license_plate_number)) + _context.yuntech_parking_user_list.Add(yuntech_parking_user_list); + try { - return Conflict(); + await _context.SaveChangesAsync(); } - else + catch (DbUpdateException) { - throw; + if (Yuntech_parking_user_listExists(yuntech_parking_user_list.user_license_plate_number)) + { + return Conflict(); + } + else + { + throw; + } } - } - return CreatedAtAction("GetYuntech_parking_user_list", new { id = yuntech_parking_user_list.user_license_plate_number }, yuntech_parking_user_list); + return Ok("ok"); + } + + return Ok("車牌重複"); } #endregion