176 lines
5.1 KiB
C#
176 lines
5.1 KiB
C#
|
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;
|
|||
|
}
|
|||
|
|
|||
|
#region 獲取校園總車輛數值
|
|||
|
/// <summary>
|
|||
|
/// 獲取校園總車輛數值
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
// 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();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 獲取單獨總車輛數據
|
|||
|
/// <summary>
|
|||
|
/// 獲取單獨總車輛數據
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <returns></returns>
|
|||
|
// 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;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 編輯剩餘車位數據
|
|||
|
/// <summary>
|
|||
|
/// 編輯剩餘車位數據
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <param name="yuntech_parking"></param>
|
|||
|
/// <returns></returns>
|
|||
|
// 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();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 新增數據
|
|||
|
/// <summary>
|
|||
|
/// 新增數據
|
|||
|
/// </summary>
|
|||
|
/// <param name="yuntech_parking"></param>
|
|||
|
/// <returns></returns>
|
|||
|
// 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);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 刪除數據
|
|||
|
/// <summary>
|
|||
|
/// 刪除數據
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <returns></returns>
|
|||
|
// 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();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
private bool Yuntech_parkingExists(string id)
|
|||
|
{
|
|||
|
return (_context.yuntech_parking?.Any(e => e.all_num == id)).GetValueOrDefault();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|