184 lines
7.5 KiB
C#
184 lines
7.5 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.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_roi_passController : ControllerBase
|
|
{
|
|
private readonly SqlContext _context;
|
|
|
|
public Parking_spaces_roi_passController(SqlContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
#region 抓出所有區域ROI範圍資料
|
|
/// <summary>
|
|
/// 抓出所有區域ROI範圍資料
|
|
/// (x1,y1為左上的點 x2,y2為右下的點)
|
|
/// roi_function 為 ROI功能 有(CAR_ROI_license_plate(車牌辨識範圍)、CAR_ROI_violation(違規區域)、CAR_ROI_normal(正常區域))
|
|
/// mode 為模式選擇 (pass(判斷車是進入或出去)、violation(判斷違規))
|
|
/// </summary>
|
|
// GET: api/Parking_spaces_roi
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<Parking_spaces_roi_pass>>> Getparking_spaces_roi_pass()
|
|
{
|
|
if (_context.parking_spaces_roi_pass == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
return await _context.parking_spaces_roi_pass.ToListAsync();
|
|
}
|
|
#endregion
|
|
|
|
#region 根據停車場名稱抓出ROI
|
|
// GET: api/Parking_spaces_roi/5
|
|
/// <summary>
|
|
/// 根據停車場名稱抓出ROI
|
|
/// </summary>
|
|
[HttpGet("{id}")]
|
|
|
|
public async Task<IEnumerable<Parking_spaces_roi_pass>> GetParking_spaces_roi(string id)
|
|
{
|
|
|
|
var parking_spaces_roi_pass = await (from c in _context.parking_spaces_roi_pass
|
|
where c.parking_spaces_name == id
|
|
select new Parking_spaces_roi_pass
|
|
{
|
|
parking_spaces_name = c.parking_spaces_name,
|
|
cam_ip = c.cam_ip,
|
|
roi_x1 = c.roi_x1,
|
|
roi_y1 = c.roi_y1,
|
|
roi_x2 = c.roi_x2,
|
|
roi_y2 = c.roi_y2,
|
|
mode = c.mode,
|
|
roi_function = c.roi_function,
|
|
data_create_time = c.data_create_time,
|
|
}
|
|
).ToListAsync();
|
|
|
|
return parking_spaces_roi_pass;
|
|
}
|
|
#endregion
|
|
|
|
#region 編輯ROI範圍
|
|
/// <summary>
|
|
/// 編輯ROI範圍
|
|
/// </summary>
|
|
// PUT: api/Parking_spaces_roi/5
|
|
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|
[HttpPut("{id}")]
|
|
public async Task<IActionResult> PutParking_spaces_roi(string id, Parking_spaces_roi_pass parking_spaces_roi_pass)
|
|
{
|
|
var parking_spaces_roi_1 = await (from c in _context.parking_spaces_roi_pass
|
|
where c.parking_spaces_name == parking_spaces_roi_pass.parking_spaces_name
|
|
where c.roi_function == parking_spaces_roi_pass.roi_function
|
|
where c.cam_ip == parking_spaces_roi_pass.cam_ip
|
|
select new Parking_spaces_roi_pass
|
|
{
|
|
parking_spaces_name = c.parking_spaces_name,
|
|
roi_function = c.roi_function,
|
|
roi_x1 = c.roi_x1,
|
|
roi_x2 = c.roi_x2,
|
|
roi_y1 = c.roi_y1,
|
|
roi_y2 = c.roi_y2,
|
|
cam_ip = c.cam_ip,
|
|
mode = c.mode,
|
|
data_create_time = c.data_create_time,
|
|
}
|
|
).FirstAsync();
|
|
_context.parking_spaces_roi_pass.Remove(parking_spaces_roi_1);
|
|
await _context.SaveChangesAsync();
|
|
parking_spaces_roi_pass.data_create_time = DateTime.Now;
|
|
_context.parking_spaces_roi_pass.Add(parking_spaces_roi_pass);
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
|
|
return NoContent();
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 新增ROI範圍
|
|
/// <summary>
|
|
/// (x1,y1為左上的點 x2,y2為右下的點)
|
|
/// roi_function 為 ROI功能 有(CAR_ROI_license_plate(車牌辨識範圍)、CAR_ROI_violation(違規區域)、CAR_ROI_normal(正常區域))
|
|
/// mode 為模式選擇 (pass(判斷車是進入或出去)、violation(判斷違規))
|
|
/// </summary>
|
|
// POST: api/Parking_spaces_roi
|
|
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|
[HttpPost]
|
|
public async Task<ActionResult<Parking_spaces_roi_pass>> PostParking_spaces_roi(Parking_spaces_roi_pass parking_spaces_roi_pass)
|
|
{
|
|
if (_context.parking_spaces_roi_pass == null)
|
|
{
|
|
return Problem("Entity set 'SqlContext.parking_spaces_roi' is null.");
|
|
}
|
|
parking_spaces_roi_pass.data_create_time = DateTime.Now;
|
|
_context.parking_spaces_roi_pass.Add(parking_spaces_roi_pass);
|
|
try
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
catch (DbUpdateException)
|
|
{
|
|
if (Parking_spaces_roi_passExists(parking_spaces_roi_pass.parking_spaces_name))
|
|
{
|
|
return Conflict();
|
|
}
|
|
else
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
return CreatedAtAction("GetParking_spaces_roi", new { id = parking_spaces_roi_pass.parking_spaces_name }, parking_spaces_roi_pass);
|
|
}
|
|
#endregion
|
|
|
|
#region 刪除ROI範圍
|
|
/// <summary>
|
|
/// 刪除ROI範圍
|
|
/// </summary>
|
|
// DELETE: api/Parking_spaces_roi/5
|
|
[HttpDelete("{id}")]
|
|
public async Task<IActionResult> DeleteParking_spaces_roi(string id)
|
|
{
|
|
if (_context.parking_spaces_roi_pass == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
var parking_spaces_roi_pass = await _context.parking_spaces_roi_pass.FindAsync(id);
|
|
if (parking_spaces_roi_pass == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
_context.parking_spaces_roi_pass.Remove(parking_spaces_roi_pass);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return NoContent();
|
|
}
|
|
#endregion
|
|
|
|
|
|
private bool Parking_spaces_roi_passExists(string id)
|
|
{
|
|
return (_context.parking_spaces_roi_pass?.Any(e => e.parking_spaces_name == id)).GetValueOrDefault();
|
|
}
|
|
}
|
|
}
|