新增與名單對比,若有符合則做後續處理

This commit is contained in:
威勝 張 2024-05-23 12:02:22 +08:00
parent 26c69c10b4
commit 6a33a903f5

View File

@ -12,6 +12,7 @@ using Parking_space_WebAPI.Authorization;
using Mysqlx;
using OfficeOpenXml;
using System.Net;
using System.Net.Http.Headers;
namespace Parking_space_WebAPI.Controllers
{
@ -274,6 +275,19 @@ namespace Parking_space_WebAPI.Controllers
// 保存更改
await _context.SaveChangesAsync();
}
// 比對名單若與名單相符合則上傳至其他API
var in_list_data = await _context.yuntech_parking_user_list.FindAsync(violation_car_table.license_plate_number);
if (in_list_data != null)
{
//傳送line
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "ykmUs2ZECQ9LDiNR4waT8w6NLXjWuYE9P8safG5xTZ6");
var content = new Dictionary<string, string>();
content.Add("message",in_list_data.user_name+" - "+in_list_data.user_license_plate_number + " 違規轉彎");
httpClient.PostAsync("https://notify-api.line.me/api/notify", new FormUrlEncodedContent(content));
}
try
{
await _context.SaveChangesAsync();
@ -366,6 +380,19 @@ namespace Parking_space_WebAPI.Controllers
}
await _context.SaveChangesAsync();
// 比對名單若與名單相符合則上傳至其他API
var in_list_data_1 = await _context.yuntech_parking_user_list.FindAsync(license_plate_number);
if (in_list_data_1 != null)
{
//傳送line
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "ykmUs2ZECQ9LDiNR4waT8w6NLXjWuYE9P8safG5xTZ6");
var content = new Dictionary<string, string>();
content.Add("message", in_list_data_1.user_name + " - " + in_list_data_1.user_license_plate_number + " 違規轉彎");
httpClient.PostAsync("https://notify-api.line.me/api/notify", new FormUrlEncodedContent(content));
}
return Ok();
}
else
@ -390,6 +417,20 @@ namespace Parking_space_WebAPI.Controllers
data.license_plate_number = license_plate_number;
_context.violation_car_table.Add(data);
await _context.SaveChangesAsync();
// 比對名單若與名單相符合則上傳至其他API
var in_list_data_1 = await _context.yuntech_parking_user_list.FindAsync(license_plate_number);
if (in_list_data_1 != null)
{
//傳送line
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "ykmUs2ZECQ9LDiNR4waT8w6NLXjWuYE9P8safG5xTZ6");
var content = new Dictionary<string, string>();
content.Add("message", in_list_data_1.user_name + " - " + in_list_data_1.user_license_plate_number + " 違規轉彎");
httpClient.PostAsync("https://notify-api.line.me/api/notify", new FormUrlEncodedContent(content));
}
return Ok();
}
}
@ -411,6 +452,19 @@ namespace Parking_space_WebAPI.Controllers
// 保存更改
await _context.SaveChangesAsync();
}
// 比對名單若與名單相符合則上傳至其他API
var in_list_data = await _context.yuntech_parking_user_list.FindAsync(license_plate_number);
if (in_list_data != null)
{
//傳送line
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "ykmUs2ZECQ9LDiNR4waT8w6NLXjWuYE9P8safG5xTZ6");
var content = new Dictionary<string, string>();
content.Add("message", in_list_data.user_name + " - " + in_list_data.user_license_plate_number + " 違規轉彎");
httpClient.PostAsync("https://notify-api.line.me/api/notify", new FormUrlEncodedContent(content));
}
return Ok();
}
#endregion