diff --git a/WebApi_data_value/Controllers/Yuntech_parkingController.cs b/WebApi_data_value/Controllers/Yuntech_parkingController.cs index b203356..78a3032 100644 --- a/WebApi_data_value/Controllers/Yuntech_parkingController.cs +++ b/WebApi_data_value/Controllers/Yuntech_parkingController.cs @@ -24,6 +24,11 @@ namespace WebApi_data_value.Controllers _context = context; } + #region 獲取校園總車輛數值 + /// + /// 獲取校園總車輛數值 + /// + /// // GET: api/Yuntech_parking [HttpGet] public async Task>> Getyuntech_parking() @@ -34,7 +39,14 @@ namespace WebApi_data_value.Controllers } return await _context.yuntech_parking.ToListAsync(); } + #endregion + #region 獲取單獨總車輛數據 + /// + /// 獲取單獨總車輛數據 + /// + /// + /// // GET: api/Yuntech_parking/5 [HttpGet("{id}")] public async Task> GetYuntech_parking(string id) @@ -52,7 +64,15 @@ namespace WebApi_data_value.Controllers return yuntech_parking; } + #endregion + #region 編輯剩餘車位數據 + /// + /// 編輯剩餘車位數據 + /// + /// + /// + /// // PUT: api/Yuntech_parking/5 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPut("{id}")] @@ -83,7 +103,14 @@ namespace WebApi_data_value.Controllers return NoContent(); } + #endregion + #region 新增數據 + /// + /// 新增數據 + /// + /// + /// // POST: api/Yuntech_parking // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPost] @@ -112,7 +139,14 @@ namespace WebApi_data_value.Controllers return CreatedAtAction("GetYuntech_parking", new { id = yuntech_parking.all_num }, yuntech_parking); } + #endregion + #region 刪除數據 + /// + /// 刪除數據 + /// + /// + /// // DELETE: api/Yuntech_parking/5 [HttpDelete("{id}")] public async Task DeleteYuntech_parking(string id) @@ -132,7 +166,7 @@ namespace WebApi_data_value.Controllers return NoContent(); } - + #endregion private bool Yuntech_parkingExists(string id) { return (_context.yuntech_parking?.Any(e => e.all_num == id)).GetValueOrDefault(); diff --git a/WebApi_data_value/Controllers/Yuntech_parking_user_listController.cs b/WebApi_data_value/Controllers/Yuntech_parking_user_listController.cs new file mode 100644 index 0000000..1123407 --- /dev/null +++ b/WebApi_data_value/Controllers/Yuntech_parking_user_listController.cs @@ -0,0 +1,176 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Parking_space_WebAPI.Services; +using WebApi_data_value.Models; +using Parking_space_WebAPI.Authorization; + +namespace WebApi_data_value.Controllers +{ + [Route("api/[controller]")] + [ApiController] + //[Authorize] + [ApiExplorerSettings(GroupName = "校園大內網")] + public class Yuntech_parking_user_listController : ControllerBase + { + private readonly SqlContext _context; + + public Yuntech_parking_user_listController(SqlContext context) + { + _context = context; + } + + #region 獲取校內停車使用者名單 + /// + /// 獲取校內停車使用者名單 + /// + /// + // GET: api/Yuntech_parking_user_list + [HttpGet] + public async Task>> Getyuntech_parking_user_list() + { + if (_context.yuntech_parking_user_list == null) + { + return NotFound(); + } + return await _context.yuntech_parking_user_list.ToListAsync(); + } + #endregion + + #region 根據車牌號碼獲取使用者資訊 + /// + /// 根據車牌號碼獲取使用者資訊 + /// + /// + /// + // GET: api/Yuntech_parking_user_list/5 + [HttpGet("{id}")] + public async Task> GetYuntech_parking_user_list(string id) + { + if (_context.yuntech_parking_user_list == null) + { + return NotFound(); + } + var yuntech_parking_user_list = await _context.yuntech_parking_user_list.FindAsync(id); + + if (yuntech_parking_user_list == null) + { + return NotFound(); + } + + return yuntech_parking_user_list; + } + #endregion + + #region 編輯校內停車場使用者名單資料 + /// + /// 編輯校內停車場使用者名單資料 + /// + /// + /// + /// + // PUT: api/Yuntech_parking_user_list/5 + // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 + [HttpPut("{id}")] + public async Task PutYuntech_parking_user_list(string id, Yuntech_parking_user_list yuntech_parking_user_list) + { + if (id != yuntech_parking_user_list.user_license_plate_number) + { + return BadRequest(); + } + + _context.Entry(yuntech_parking_user_list).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!Yuntech_parking_user_listExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + #endregion + + #region 新增校內停車場使用者名單 + /// + /// 新增校內停車場使用者名單 + /// + /// + /// + // POST: api/Yuntech_parking_user_list + // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 + [HttpPost] + public async Task> PostYuntech_parking_user_list(Yuntech_parking_user_list yuntech_parking_user_list) + { + if (_context.yuntech_parking_user_list == null) + { + return Problem("Entity set 'SqlContext.yuntech_parking_user_list' is null."); + } + _context.yuntech_parking_user_list.Add(yuntech_parking_user_list); + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateException) + { + 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); + } + #endregion + + #region 刪除校內停車場使用者名單資料 + /// + /// 刪除校內停車場使用者名單資料 + /// + /// + /// + // DELETE: api/Yuntech_parking_user_list/5 + [HttpDelete("{id}")] + public async Task DeleteYuntech_parking_user_list(string id) + { + if (_context.yuntech_parking_user_list == null) + { + return NotFound(); + } + var yuntech_parking_user_list = await _context.yuntech_parking_user_list.FindAsync(id); + if (yuntech_parking_user_list == null) + { + return NotFound(); + } + + _context.yuntech_parking_user_list.Remove(yuntech_parking_user_list); + await _context.SaveChangesAsync(); + + return NoContent(); + } + #endregion + + private bool Yuntech_parking_user_listExists(string id) + { + return (_context.yuntech_parking_user_list?.Any(e => e.user_license_plate_number == id)).GetValueOrDefault(); + } + } +} diff --git a/WebApi_data_value/Models/Yuntech_parking_user_list.cs b/WebApi_data_value/Models/Yuntech_parking_user_list.cs new file mode 100644 index 0000000..9b90fcf --- /dev/null +++ b/WebApi_data_value/Models/Yuntech_parking_user_list.cs @@ -0,0 +1,10 @@ +namespace WebApi_data_value.Models +{ + public class Yuntech_parking_user_list + { + public string? user_name { get; set; } = null; + public string? user_license_plate_number { get; set; }=null; + public string? user_state_check { get; set; } = null; + + } +} diff --git a/WebApi_data_value/Services/SqlContext.cs b/WebApi_data_value/Services/SqlContext.cs index 87a1983..48b815c 100644 --- a/WebApi_data_value/Services/SqlContext.cs +++ b/WebApi_data_value/Services/SqlContext.cs @@ -47,7 +47,7 @@ namespace Parking_space_WebAPI.Services // 演算法 public DbSet parking_space_algorithm { get; set; } = null!; - //大門口 + //進入車輛 public DbSet yuntech_in_car_table { get; set; } = null!; //雲科校內相機 @@ -55,6 +55,9 @@ namespace Parking_space_WebAPI.Services public DbSet yuntech_cam { get; set; } = null!; public DbSet yuntech_parking { get; set; } = null!; + // 雲科登記車輛名單 + public DbSet yuntech_parking_user_list { get; set; } = null!; + protected override void OnModelCreating(ModelBuilder builder) { @@ -86,6 +89,8 @@ namespace Parking_space_WebAPI.Services builder.Entity().HasKey(o => new { o.ip }); //Primary Key builder.Entity().HasKey(o => new { o.all_num }); //Primary Key + + builder.Entity().HasKey(o => new { o.user_license_plate_number });//Primary Key }