新增註解 新增時間搜尋 新增車牌搜尋

This commit is contained in:
威勝 張 2024-02-05 22:09:54 +08:00
parent 53287bb390
commit e210b04ef3
3 changed files with 217 additions and 44 deletions

View File

@ -21,7 +21,13 @@ namespace WebApi_data_value.Controllers
_context = context; _context = context;
} }
#region
// GET: api/Parking_spaces_violation_total_table // GET: api/Parking_spaces_violation_total_table
/// <summary>
/// 獲取所有違規區域名稱
/// </summary>
/// <returns></returns>
[HttpGet] [HttpGet]
public async Task<ActionResult<IEnumerable<Parking_spaces_violation_total_table>>> Getparking_spaces_violation_total_table() public async Task<ActionResult<IEnumerable<Parking_spaces_violation_total_table>>> Getparking_spaces_violation_total_table()
{ {
@ -31,7 +37,14 @@ namespace WebApi_data_value.Controllers
} }
return await _context.parking_spaces_violation_total_table.ToListAsync(); return await _context.parking_spaces_violation_total_table.ToListAsync();
} }
#endregion
#region
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
// GET: api/Parking_spaces_violation_total_table/5 // GET: api/Parking_spaces_violation_total_table/5
[HttpGet("{id}")] [HttpGet("{id}")]
public async Task<ActionResult<Parking_spaces_violation_total_table>> GetParking_spaces_violation_total_table(string id) public async Task<ActionResult<Parking_spaces_violation_total_table>> GetParking_spaces_violation_total_table(string id)
@ -49,7 +62,15 @@ namespace WebApi_data_value.Controllers
return parking_spaces_violation_total_table; return parking_spaces_violation_total_table;
} }
#endregion
#region
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="parking_spaces_violation_total_table"></param>
/// <returns></returns>
// PUT: api/Parking_spaces_violation_total_table/5 // PUT: api/Parking_spaces_violation_total_table/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")] [HttpPut("{id}")]
@ -80,7 +101,15 @@ namespace WebApi_data_value.Controllers
return NoContent(); return NoContent();
} }
#endregion
#region
/// <summary>
///
/// </summary>
/// <param name="parking_spaces_violation_total_table"></param>
/// <returns></returns>
// POST: api/Parking_spaces_violation_total_table // POST: api/Parking_spaces_violation_total_table
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost] [HttpPost]
@ -109,7 +138,14 @@ namespace WebApi_data_value.Controllers
return CreatedAtAction("GetParking_spaces_violation_total_table", new { id = parking_spaces_violation_total_table.parking_spaces_violation_name }, parking_spaces_violation_total_table); return CreatedAtAction("GetParking_spaces_violation_total_table", new { id = parking_spaces_violation_total_table.parking_spaces_violation_name }, parking_spaces_violation_total_table);
} }
#endregion
#region
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
// DELETE: api/Parking_spaces_violation_total_table/5 // DELETE: api/Parking_spaces_violation_total_table/5
[HttpDelete("{id}")] [HttpDelete("{id}")]
public async Task<IActionResult> DeleteParking_spaces_violation_total_table(string id) public async Task<IActionResult> DeleteParking_spaces_violation_total_table(string id)
@ -129,7 +165,7 @@ namespace WebApi_data_value.Controllers
return NoContent(); return NoContent();
} }
#endregion
private bool Parking_spaces_violation_total_tableExists(string id) private bool Parking_spaces_violation_total_tableExists(string id)
{ {
return (_context.parking_spaces_violation_total_table?.Any(e => e.parking_spaces_violation_name == id)).GetValueOrDefault(); return (_context.parking_spaces_violation_total_table?.Any(e => e.parking_spaces_violation_name == id)).GetValueOrDefault();

View File

@ -22,20 +22,34 @@ namespace WebApi_data_value.Controllers
_context = context; _context = context;
} }
#region #region
/// <summary>
/// 抓取所有違規車輛
/// </summary>
/// <returns></returns>
// GET: api/Violation_car_table // GET: api/Violation_car_table
[HttpGet] [HttpGet]
public async Task<ActionResult<IEnumerable<Violation_car_table>>> Getviolation_car_table() public async Task<ActionResult<IEnumerable<Violation_car_table>>> Getviolation_car_table()
{ {
if (_context.violation_car_table == null) var violation_car_table = await(from c in _context.violation_car_table
orderby c.create_data_time descending
select new Violation_car_table
{ {
return NotFound(); license_plate_number = c.license_plate_number,
} create_data_time = c.create_data_time,
return await _context.violation_car_table.ToListAsync(); violation_location_name=c.violation_location_name,
}).ToListAsync();
return violation_car_table;
} }
#endregion #endregion
#region #region
/// <summary>
/// 透過區域名稱抓取違規車輛
/// </summary>
/// <param name="id">違規區域</param>
/// <returns></returns>
// GET: api/Violation_car_table/5 // GET: api/Violation_car_table/5
[HttpGet("violation_location_name-{id}")] [HttpGet("violation_location_name-{id}")]
public async Task<IEnumerable<Single_violation_car_table>> GetViolation_car_table(string id) public async Task<IEnumerable<Single_violation_car_table>> GetViolation_car_table(string id)
@ -59,6 +73,12 @@ namespace WebApi_data_value.Controllers
#endregion #endregion
#region #region
/// <summary>
/// 抓出指定違規車輛
/// </summary>
/// <param name="id">違規區域</param>
/// <param name="time">資料新增時間</param>
/// <returns></returns>
[HttpGet("location_nam-{id}-time-{time}")] [HttpGet("location_nam-{id}-time-{time}")]
public async Task<ActionResult<Violation_car_table>> violation_location_name(string id, DateTime time) public async Task<ActionResult<Violation_car_table>> violation_location_name(string id, DateTime time)
{ {
@ -83,6 +103,12 @@ namespace WebApi_data_value.Controllers
#region #region
/// <summary>
/// 更新指定違規車輛
/// </summary>
/// <param name="id">區域</param>
/// <param name="time">資料新增時間</param>
/// <returns></returns>
[HttpPut("location_nam-{id}-time-{time}")] [HttpPut("location_nam-{id}-time-{time}")]
public async Task<IActionResult> PutViolation_car_table(string id, DateTime time,Violation_car_table violation_car_table) public async Task<IActionResult> PutViolation_car_table(string id, DateTime time,Violation_car_table violation_car_table)
{ {
@ -100,41 +126,65 @@ namespace WebApi_data_value.Controllers
} }
#endregion #endregion
#region
/// <summary>
/// 獲取時間內的車輛
/// </summary>
/// <param name="id">位置名稱</param>
/// <param name="start_time">起始時間</param>
/// <param name="end_time">結束時間</param>
/// <returns></returns>
[HttpGet("location_name_1_-{id}-start_time-{start_time}-end_time-{end_time}")]
public async Task<IEnumerable<Single_violation_car_table>> GetYuntech_in_car_table_date(string id, DateTime start_time, DateTime end_time)
{
/* var violation_car_table = await (from c in _context.violation_car_table
// PUT: api/Violation_car_table/5 where c.violation_location_name == id
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 where c.create_data_time >= start_time
[HttpPut("{id}")] where c.create_data_time <= end_time
public async Task<IActionResult> PutViolation_car_table(string id, Violation_car_table violation_car_table) select new Single_violation_car_table
{ {
if (id != violation_car_table.violation_location_name) violation_location_name = c.violation_location_name,
{ license_plate_number = c.license_plate_number,
return BadRequest(); create_data_time = c.create_data_time,
} }).ToListAsync();
_context.Entry(violation_car_table).State = EntityState.Modified;
try return violation_car_table;
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!Violation_car_tableExists(id))
{
return NotFound();
}
else
{
throw;
}
} }
#endregion
return NoContent(); #region
/// <summary>
/// 透過車牌號碼搜尋所有資料
/// </summary>
/// <param name="id">車牌號碼 ex:ABC4321</param>
/// <returns></returns>
[HttpGet("license_plate_number-{id}")]
public async Task<IEnumerable<Single_violation_car_table>> Getlicense_plate_number(string id)
{
var in_car_table = await (from c in _context.violation_car_table
where c.license_plate_number == id
orderby c.create_data_time descending
select new Single_violation_car_table
{
violation_location_name = c.violation_location_name,
license_plate_number = c.license_plate_number,
create_data_time = c.create_data_time,
}).ToListAsync();
return in_car_table;
} }
*/ #endregion
#region #region
/// <summary>
/// 新增違規車輛
/// </summary>
/// <param name="violation_car_table"></param>
/// <returns></returns>
// POST: api/Violation_car_table // POST: api/Violation_car_table
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost] [HttpPost]
@ -167,6 +217,12 @@ namespace WebApi_data_value.Controllers
#endregion #endregion
#region #region
/// <summary>
/// 刪除違規車輛
/// </summary>
/// <param name="id"></param>
/// <param name="time"></param>
/// <returns></returns>
// DELETE: api/Violation_car_table/5 // DELETE: api/Violation_car_table/5
[HttpDelete("location_name-{id}-time-{time}")] [HttpDelete("location_name-{id}-time-{time}")]
public async Task<IActionResult> DeleteViolation_car_table(string id, DateTime time) public async Task<IActionResult> DeleteViolation_car_table(string id, DateTime time)

View File

@ -11,6 +11,7 @@ using WebApi_data_value.ViewModel;
namespace WebApi_data_value.Controllers namespace WebApi_data_value.Controllers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
public class Yuntech_in_car_tableController : ControllerBase public class Yuntech_in_car_tableController : ControllerBase
@ -21,7 +22,10 @@ namespace WebApi_data_value.Controllers
{ {
_context = context; _context = context;
} }
#region
/// <summary>
/// 獲取進入雲科的所有資料
/// </summary>
// GET: api/Yuntech_in_car_table // GET: api/Yuntech_in_car_table
[HttpGet] [HttpGet]
public async Task<ActionResult<IEnumerable<Yuntech_in_car_table>>> Getyuntech_in_car_table() public async Task<ActionResult<IEnumerable<Yuntech_in_car_table>>> Getyuntech_in_car_table()
@ -40,9 +44,14 @@ namespace WebApi_data_value.Controllers
return in_car_table; return in_car_table;
} }
#endregion
#region #region
/// <summary>
/// 獲取進入的單獨地區的所有資料
/// </summary>
/// <param name="id"> 哪個門口</param>
/// <returns></returns>
// GET: api/Yuntech_in_car_table/5 // GET: api/Yuntech_in_car_table/5
[HttpGet("location-{id}")] [HttpGet("location-{id}")]
public async Task<IEnumerable<Yuntech_in_car_table>> GetYuntech_in_car_table(string id) public async Task<IEnumerable<Yuntech_in_car_table>> GetYuntech_in_car_table(string id)
@ -56,23 +65,90 @@ namespace WebApi_data_value.Controllers
in_time = c.in_time, in_time = c.in_time,
out_time = c.out_time, out_time = c.out_time,
location = c.location, location = c.location,
} }).ToListAsync();
).ToListAsync();
return in_car_table; return in_car_table;
} }
#endregion #endregion
#region #region
/// <summary>
/// 獲取時間內的車輛
/// </summary>
/// <param name="id">位置名稱</param>
/// <param name="start_time">起始時間</param>
/// <param name="end_time">結束時間</param>
/// <returns></returns>
[HttpGet("location_name_1_-{id}-start_time-{start_time}-end_time-{end_time}")]
public async Task<IEnumerable<Yuntech_in_car_table>> GetYuntech_in_car_table_date(string id,DateTime start_time, DateTime end_time)
{
var in_car_table = await (from c in _context.yuntech_in_car_table
where c.location == id
where c.in_time >= start_time
where c.in_time <= end_time
select new Yuntech_in_car_table
{
license_plate_number = c.license_plate_number,
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
}).ToListAsync();
return in_car_table;
}
#endregion
#region
/// <summary>
/// 透過車牌號碼搜尋所有資料
/// </summary>
/// <param name="id">車牌號碼 ex:ABC4321</param>
/// <returns></returns>
[HttpGet("license_plate_number-{id}")]
public async Task<IEnumerable<Yuntech_in_car_table>> Getlicense_plate_number(string id)
{
var in_car_table = await (from c in _context.yuntech_in_car_table
where c.license_plate_number == id
orderby c.in_time descending
select new Yuntech_in_car_table
{
license_plate_number = c.license_plate_number,
in_time = c.in_time,
out_time = c.out_time,
location = c.location,
}).ToListAsync();
return in_car_table;
}
#endregion
#region
/// <summary>
/// 獲取進入的單獨地區的單筆資料
/// </summary>
/// <param name="id">地區</param>
/// <param name="time">進入時間 ex:2024-02-05T12:21:48.395Z</param>
/// <returns></returns>
// GET: api/Yuntech_in_car_table/5 // GET: api/Yuntech_in_car_table/5
[HttpGet("location-{id}-time-{time}")] [HttpGet("location_name-{id}-time-{time}")]
public async Task<ActionResult<Yuntech_in_car_table>> One_data(string id, DateTime time) public async Task<ActionResult<Yuntech_in_car_table>> One_data(string id, DateTime time)
{ {
var in_car_table = await (from c in _context.yuntech_in_car_table var in_car_table = await (from c in _context.yuntech_in_car_table
where c.location == id where c.location == id
where c.in_time == time where c.in_time == time
select c).FirstAsync(); select new Yuntech_in_car_table
{
license_plate_number= c.license_plate_number,
in_time = c.in_time,
out_time = c.out_time,
car_img = c.car_img,
location = c.location,
}).FirstAsync();
return in_car_table; return in_car_table;
@ -81,7 +157,12 @@ namespace WebApi_data_value.Controllers
#region
/// <summary>
/// 新增進入雲科的車輛資料
/// </summary>
/// <param name="yuntech_in_car_table"></param>
/// <returns></returns>
// POST: api/Yuntech_in_car_table // POST: api/Yuntech_in_car_table
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost] [HttpPost]
@ -112,7 +193,7 @@ namespace WebApi_data_value.Controllers
return CreatedAtAction("GetYuntech_in_car_table", new { id = yuntech_in_car_table.in_time }, yuntech_in_car_table); return CreatedAtAction("GetYuntech_in_car_table", new { id = yuntech_in_car_table.in_time }, yuntech_in_car_table);
} }
#endregion
private bool Yuntech_in_car_tableExists(DateTime? id) private bool Yuntech_in_car_tableExists(DateTime? id)