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