diff --git a/WebApi_data_value/Controllers/Parking_spaces_violation_total_tableController.cs b/WebApi_data_value/Controllers/Parking_spaces_violation_total_tableController.cs index c3e1dff..79b01a3 100644 --- a/WebApi_data_value/Controllers/Parking_spaces_violation_total_tableController.cs +++ b/WebApi_data_value/Controllers/Parking_spaces_violation_total_tableController.cs @@ -21,7 +21,13 @@ namespace WebApi_data_value.Controllers _context = context; } + #region // GET: api/Parking_spaces_violation_total_table + /// + /// 獲取所有違規區域名稱 + /// + /// + [HttpGet] public async Task>> Getparking_spaces_violation_total_table() { @@ -31,7 +37,14 @@ namespace WebApi_data_value.Controllers } return await _context.parking_spaces_violation_total_table.ToListAsync(); } - + #endregion + + #region + /// + /// + /// + /// + /// // GET: api/Parking_spaces_violation_total_table/5 [HttpGet("{id}")] public async Task> GetParking_spaces_violation_total_table(string id) @@ -49,7 +62,15 @@ namespace WebApi_data_value.Controllers return parking_spaces_violation_total_table; } + #endregion + #region + /// + /// + /// + /// + /// + /// // PUT: api/Parking_spaces_violation_total_table/5 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPut("{id}")] @@ -80,7 +101,15 @@ namespace WebApi_data_value.Controllers return NoContent(); } + #endregion + + #region + /// + /// + /// + /// + /// // POST: api/Parking_spaces_violation_total_table // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [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); } + #endregion + #region + /// + /// + /// + /// + /// // DELETE: api/Parking_spaces_violation_total_table/5 [HttpDelete("{id}")] public async Task DeleteParking_spaces_violation_total_table(string id) @@ -129,7 +165,7 @@ namespace WebApi_data_value.Controllers return NoContent(); } - + #endregion 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(); diff --git a/WebApi_data_value/Controllers/Violation_car_tableController.cs b/WebApi_data_value/Controllers/Violation_car_tableController.cs index 968a0e4..113c0f2 100644 --- a/WebApi_data_value/Controllers/Violation_car_tableController.cs +++ b/WebApi_data_value/Controllers/Violation_car_tableController.cs @@ -22,20 +22,34 @@ namespace WebApi_data_value.Controllers _context = context; } #region 抓取所有違規車輛 + /// + /// 抓取所有違規車輛 + /// + /// // GET: api/Violation_car_table [HttpGet] public async Task>> Getviolation_car_table() { - if (_context.violation_car_table == null) - { - return NotFound(); - } - return await _context.violation_car_table.ToListAsync(); + var violation_car_table = await(from c in _context.violation_car_table + orderby c.create_data_time descending + select new Violation_car_table + { + license_plate_number = c.license_plate_number, + create_data_time = c.create_data_time, + violation_location_name=c.violation_location_name, + + }).ToListAsync(); + return violation_car_table; } #endregion #region 透過區域名稱抓取違規車輛 + /// + /// 透過區域名稱抓取違規車輛 + /// + /// 違規區域 + /// // GET: api/Violation_car_table/5 [HttpGet("violation_location_name-{id}")] public async Task> GetViolation_car_table(string id) @@ -59,6 +73,12 @@ namespace WebApi_data_value.Controllers #endregion #region 抓出指定違規車輛 + /// + /// 抓出指定違規車輛 + /// + /// 違規區域 + /// 資料新增時間 + /// [HttpGet("location_nam-{id}-time-{time}")] public async Task> violation_location_name(string id, DateTime time) { @@ -83,6 +103,12 @@ namespace WebApi_data_value.Controllers #region 更新指定違規車輛 + /// + /// 更新指定違規車輛 + /// + /// 區域 + /// 資料新增時間 + /// [HttpPut("location_nam-{id}-time-{time}")] public async Task PutViolation_car_table(string id, DateTime time,Violation_car_table violation_car_table) { @@ -100,41 +126,65 @@ namespace WebApi_data_value.Controllers } #endregion - - /* - // PUT: api/Violation_car_table/5 - // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 - [HttpPut("{id}")] - public async Task PutViolation_car_table(string id, Violation_car_table violation_car_table) + #region 獲取時間內的資料 + /// + /// 獲取時間內的車輛 + /// + /// 位置名稱 + /// 起始時間 + /// 結束時間 + /// + [HttpGet("location_name_1_-{id}-start_time-{start_time}-end_time-{end_time}")] + public async Task> GetYuntech_in_car_table_date(string id, DateTime start_time, DateTime end_time) { - if (id != violation_car_table.violation_location_name) - { - return BadRequest(); - } - _context.Entry(violation_car_table).State = EntityState.Modified; + var violation_car_table = await (from c in _context.violation_car_table + where c.violation_location_name == id + where c.create_data_time >= start_time + where c.create_data_time <= end_time + 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(); - try - { - await _context.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!Violation_car_tableExists(id)) - { - return NotFound(); - } - else - { - throw; - } - } - return NoContent(); + return violation_car_table; } - */ + #endregion + + #region 透過車牌號碼搜尋所有資料 + /// + /// 透過車牌號碼搜尋所有資料 + /// + /// 車牌號碼 ex:ABC4321 + /// + [HttpGet("license_plate_number-{id}")] + public async Task> 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 新增違規車輛 + /// + /// 新增違規車輛 + /// + /// + /// // POST: api/Violation_car_table // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPost] @@ -167,6 +217,12 @@ namespace WebApi_data_value.Controllers #endregion #region 刪除違規車輛 + /// + /// 刪除違規車輛 + /// + /// + /// + /// // DELETE: api/Violation_car_table/5 [HttpDelete("location_name-{id}-time-{time}")] public async Task DeleteViolation_car_table(string id, DateTime time) diff --git a/WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs b/WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs index 5c77873..373fa3e 100644 --- a/WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs +++ b/WebApi_data_value/Controllers/Yuntech_in_car_tableController.cs @@ -11,6 +11,7 @@ using WebApi_data_value.ViewModel; namespace WebApi_data_value.Controllers { + [Route("api/[controller]")] [ApiController] public class Yuntech_in_car_tableController : ControllerBase @@ -21,7 +22,10 @@ namespace WebApi_data_value.Controllers { _context = context; } - + #region 獲取進入雲科的所有資料 + /// + /// 獲取進入雲科的所有資料 + /// // GET: api/Yuntech_in_car_table [HttpGet] public async Task>> Getyuntech_in_car_table() @@ -40,9 +44,14 @@ namespace WebApi_data_value.Controllers return in_car_table; } - + #endregion #region 獲取進入的單獨地區的所有資料 + /// + /// 獲取進入的單獨地區的所有資料 + /// + /// 哪個門口 + /// // GET: api/Yuntech_in_car_table/5 [HttpGet("location-{id}")] public async Task> GetYuntech_in_car_table(string id) @@ -56,23 +65,90 @@ namespace WebApi_data_value.Controllers in_time = c.in_time, out_time = c.out_time, location = c.location, - } - ).ToListAsync(); + }).ToListAsync(); return in_car_table; } #endregion - #region 獲取進入的單獨地區的所有資料 + #region 獲取時間內的車輛 + /// + /// 獲取時間內的車輛 + /// + /// 位置名稱 + /// 起始時間 + /// 結束時間 + /// + [HttpGet("location_name_1_-{id}-start_time-{start_time}-end_time-{end_time}")] + public async Task> 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 透過車牌號碼搜尋所有資料 + /// + /// 透過車牌號碼搜尋所有資料 + /// + /// 車牌號碼 ex:ABC4321 + /// + [HttpGet("license_plate_number-{id}")] + public async Task> 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 獲取進入的單獨地區的單筆資料 + /// + /// 獲取進入的單獨地區的單筆資料 + /// + /// 地區 + /// 進入時間 ex:2024-02-05T12:21:48.395Z + /// // GET: api/Yuntech_in_car_table/5 - [HttpGet("location-{id}-time-{time}")] + [HttpGet("location_name-{id}-time-{time}")] public async Task> One_data(string id, DateTime time) { var in_car_table = await (from c in _context.yuntech_in_car_table where c.location == id 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; @@ -81,7 +157,12 @@ namespace WebApi_data_value.Controllers - + #region 新增資料 + /// + /// 新增進入雲科的車輛資料 + /// + /// + /// // POST: api/Yuntech_in_car_table // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPost] @@ -112,8 +193,8 @@ namespace WebApi_data_value.Controllers 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) {