2024-05-02 12:27:53 +08:00
|
|
|
|
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_parkingController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlContext _context;
|
|
|
|
|
|
|
|
|
|
public Yuntech_parkingController(SqlContext context)
|
|
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-21 15:02:04 +08:00
|
|
|
|
#region 獲取校園總車輛數值
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 獲取校園總車輛數值
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-05-02 12:27:53 +08:00
|
|
|
|
// GET: api/Yuntech_parking
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult<IEnumerable<Yuntech_parking>>> Getyuntech_parking()
|
|
|
|
|
{
|
|
|
|
|
if (_context.yuntech_parking == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
return await _context.yuntech_parking.ToListAsync();
|
|
|
|
|
}
|
2024-05-21 15:02:04 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 獲取單獨總車輛數據
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 獲取單獨總車輛數據
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-05-02 12:27:53 +08:00
|
|
|
|
// GET: api/Yuntech_parking/5
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
public async Task<ActionResult<Yuntech_parking>> GetYuntech_parking(string id)
|
|
|
|
|
{
|
|
|
|
|
if (_context.yuntech_parking == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
var yuntech_parking = await _context.yuntech_parking.FindAsync(id);
|
|
|
|
|
|
|
|
|
|
if (yuntech_parking == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return yuntech_parking;
|
|
|
|
|
}
|
2024-05-21 15:02:04 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 編輯剩餘車位數據
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 編輯剩餘車位數據
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="yuntech_parking"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-05-02 12:27:53 +08:00
|
|
|
|
// PUT: api/Yuntech_parking/5
|
|
|
|
|
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|
|
|
|
[HttpPut("{id}")]
|
|
|
|
|
public async Task<IActionResult> PutYuntech_parking(string id, Yuntech_parking yuntech_parking)
|
|
|
|
|
{
|
|
|
|
|
if (id != yuntech_parking.all_num)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_context.Entry(yuntech_parking).State = EntityState.Modified;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
catch (DbUpdateConcurrencyException)
|
|
|
|
|
{
|
|
|
|
|
if (!Yuntech_parkingExists(id))
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
2024-05-21 15:02:04 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 新增數據
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新增數據
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="yuntech_parking"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-05-02 12:27:53 +08:00
|
|
|
|
// POST: api/Yuntech_parking
|
|
|
|
|
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<ActionResult<Yuntech_parking>> PostYuntech_parking(Yuntech_parking yuntech_parking)
|
|
|
|
|
{
|
|
|
|
|
if (_context.yuntech_parking == null)
|
|
|
|
|
{
|
|
|
|
|
return Problem("Entity set 'SqlContext.yuntech_parking' is null.");
|
|
|
|
|
}
|
|
|
|
|
_context.yuntech_parking.Add(yuntech_parking);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
catch (DbUpdateException)
|
|
|
|
|
{
|
|
|
|
|
if (Yuntech_parkingExists(yuntech_parking.all_num))
|
|
|
|
|
{
|
|
|
|
|
return Conflict();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return CreatedAtAction("GetYuntech_parking", new { id = yuntech_parking.all_num }, yuntech_parking);
|
|
|
|
|
}
|
2024-05-21 15:02:04 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 刪除數據
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 刪除數據
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-05-02 12:27:53 +08:00
|
|
|
|
// DELETE: api/Yuntech_parking/5
|
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
public async Task<IActionResult> DeleteYuntech_parking(string id)
|
|
|
|
|
{
|
|
|
|
|
if (_context.yuntech_parking == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
var yuntech_parking = await _context.yuntech_parking.FindAsync(id);
|
|
|
|
|
if (yuntech_parking == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_context.yuntech_parking.Remove(yuntech_parking);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
2024-05-21 15:02:04 +08:00
|
|
|
|
#endregion
|
2024-05-02 12:27:53 +08:00
|
|
|
|
private bool Yuntech_parkingExists(string id)
|
|
|
|
|
{
|
|
|
|
|
return (_context.yuntech_parking?.Any(e => e.all_num == id)).GetValueOrDefault();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|