150 lines
5.6 KiB
C#
150 lines
5.6 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Security.Policy;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using Microsoft.AspNetCore.Http;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using Microsoft.EntityFrameworkCore;
|
|||
|
using Parking_space_WebAPI.Models;
|
|||
|
using Parking_space_WebAPI.Services;
|
|||
|
using Parking_space_WebAPI.Authorization;
|
|||
|
|
|||
|
namespace Parking_space_WebAPI.Controllers
|
|||
|
{
|
|||
|
[Route("api/[controller]")]
|
|||
|
[ApiController]
|
|||
|
[Authorize]
|
|||
|
[ApiExplorerSettings(GroupName = "校園外網")]
|
|||
|
public class Parking_spaces_cam_ptzController : ControllerBase
|
|||
|
{
|
|||
|
private readonly SqlContext _context;
|
|||
|
|
|||
|
public Parking_spaces_cam_ptzController(SqlContext context)
|
|||
|
{
|
|||
|
_context = context;
|
|||
|
}
|
|||
|
|
|||
|
#region 根據停車場名稱獲取cam_ptz的資料
|
|||
|
// GET: api/Parking_spaces_cam
|
|||
|
/// <summary>
|
|||
|
/// 根據停車場名稱獲取cam_ptz的資料
|
|||
|
/// </summary>
|
|||
|
[HttpGet("parking_spaces_name-{id}")]
|
|||
|
public async Task<IEnumerable<Parking_spaces_cam_ptz>> Getparking_spaces_cam(string id)
|
|||
|
{
|
|||
|
var parking_spaces_cam_ptz = await (from c in _context.parking_spaces_cam_ptz
|
|||
|
where c.parking_spaces_name == id
|
|||
|
select new Parking_spaces_cam_ptz
|
|||
|
{
|
|||
|
parking_spaces_name = c.parking_spaces_name,
|
|||
|
mode = c.mode,
|
|||
|
rtsp_url = c.rtsp_url,
|
|||
|
http_port = c.http_port,
|
|||
|
rtsp_port = c.rtsp_port,
|
|||
|
img = c.img,
|
|||
|
pan = c.pan,
|
|||
|
titl = c.titl,
|
|||
|
zoom = c.zoom,
|
|||
|
|
|||
|
}).ToListAsync();
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
return parking_spaces_cam_ptz;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
// PUT: api/Parking_spaces_cam_ptz/5
|
|||
|
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|||
|
[HttpPut("parking_spaces_name-{id}-IP-{ip}-port-{port}")]
|
|||
|
public async Task<IActionResult> PutParking_spaces_cam_ptz(string id, string ip, string port, Parking_spaces_cam_ptz parking_spaces_cam_ptz)
|
|||
|
{
|
|||
|
var parking_spaces_cam = await (from c in _context.parking_spaces_cam
|
|||
|
where c.parking_spaces_name == id
|
|||
|
where c.ip == ip
|
|||
|
where c.port == port
|
|||
|
select new Parking_spaces_cam
|
|||
|
{
|
|||
|
parking_spaces_name = c.parking_spaces_name,
|
|||
|
ip = ip,
|
|||
|
port = port,
|
|||
|
url = c.url
|
|||
|
}
|
|||
|
).FirstAsync();
|
|||
|
var url = parking_spaces_cam.url;
|
|||
|
if (url != parking_spaces_cam_ptz.rtsp_url)
|
|||
|
{
|
|||
|
return BadRequest();
|
|||
|
}
|
|||
|
|
|||
|
_context.Entry(parking_spaces_cam_ptz).State = EntityState.Modified;
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
await _context.SaveChangesAsync();
|
|||
|
}
|
|||
|
catch (DbUpdateConcurrencyException)
|
|||
|
{
|
|||
|
if (!Parking_spaces_cam_ptzExists(id))
|
|||
|
{
|
|||
|
return NotFound();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return NoContent();
|
|||
|
}
|
|||
|
|
|||
|
#region 新增cam_ptz資料
|
|||
|
// POST: api/Parking_spaces_cam
|
|||
|
/// <summary>
|
|||
|
/// 新增cam_ptz資料
|
|||
|
/// </summary>
|
|||
|
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|||
|
[HttpPost]
|
|||
|
public async Task<ActionResult<Parking_spaces_cam_ptz>> PostParking_spaces_cam(Parking_spaces_cam_ptz parking_spaces_cam_ptz)
|
|||
|
{
|
|||
|
if (_context.parking_spaces_cam_ptz == null)
|
|||
|
{
|
|||
|
return Problem("Entity set 'SqlContext.parking_spaces_cam_ptz' is null.");
|
|||
|
}
|
|||
|
_context.parking_spaces_cam_ptz.Add(parking_spaces_cam_ptz);
|
|||
|
await _context.SaveChangesAsync();
|
|||
|
|
|||
|
return NoContent();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
// DELETE: api/Parking_spaces_cam_ptz/5
|
|||
|
[HttpDelete("{id}")]
|
|||
|
public async Task<IActionResult> DeleteParking_spaces_cam_ptz(string id)
|
|||
|
{
|
|||
|
if (_context.parking_spaces_cam_ptz == null)
|
|||
|
{
|
|||
|
return NotFound();
|
|||
|
}
|
|||
|
var parking_spaces_cam_ptz = await _context.parking_spaces_cam_ptz.FindAsync(id);
|
|||
|
if (parking_spaces_cam_ptz == null)
|
|||
|
{
|
|||
|
return NotFound();
|
|||
|
}
|
|||
|
|
|||
|
_context.parking_spaces_cam_ptz.Remove(parking_spaces_cam_ptz);
|
|||
|
await _context.SaveChangesAsync();
|
|||
|
|
|||
|
return NoContent();
|
|||
|
}
|
|||
|
|
|||
|
private bool Parking_spaces_cam_ptzExists(string id)
|
|||
|
{
|
|||
|
return (_context.parking_spaces_cam_ptz?.Any(e => e.rtsp_url == id)).GetValueOrDefault();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|