parking-webapi/WebApi_data_value/Controllers/Parking_spaces_roi_violationController.cs

137 lines
6.0 KiB
C#
Raw Normal View History

2024-09-28 01:25:42 +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.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_violationController : ControllerBase
{
private readonly SqlContext _context;
public Parking_spaces_roi_violationController(SqlContext context)
{
_context = context;
}
#region ROI
// GET: api/Parking_spaces_roi/5
/// <summary>
/// 根據停車場名稱抓出ROI
/// </summary>
[HttpGet("parking_spaces_name-{id}")]
public async Task<IEnumerable<Parking_spaces_roi_violation>> GetParking_spaces_roi_violation(string id)
{
var parking_spaces_roi_violation = await (from c in _context.parking_spaces_roi_violation
where c.parking_spaces_name == id
select new Parking_spaces_roi_violation
{
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,
serial_num = c.serial_num,
}
).ToListAsync();
return parking_spaces_roi_violation;
}
#endregion
#region ROI範圍
// PUT: api/Parking_spaces_roi_violation/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("parking_spaces_name-{id}-serial_num-{num}")]
public async Task<IActionResult> PutParking_spaces_roi_violation(string id, string num, Parking_spaces_roi_violation parking_spaces_roi_violation)
{
var parking_spaces_roi_violation_1 = await(from c in _context.parking_spaces_roi_violation
where c.parking_spaces_name == id && c.serial_num == num
select new Parking_spaces_roi_violation
{
parking_spaces_name = c.parking_spaces_name,
serial_num = c.serial_num,
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,
mode = c.mode,
data_create_time = c.data_create_time,
cam_ip = c.cam_ip,
}).FirstAsync();
var stop = 1;
_context.parking_spaces_roi_violation.Remove(parking_spaces_roi_violation_1);
await _context.SaveChangesAsync();
parking_spaces_roi_violation.data_create_time = DateTime.Now;
_context.parking_spaces_roi_violation.Add(parking_spaces_roi_violation);
await _context.SaveChangesAsync();
return NoContent();
}
#endregion
#region roi資料
// POST: api/Parking_spaces_roi_violation
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Parking_spaces_roi_violation>> PostParking_spaces_roi_violation(Parking_spaces_roi_violation parking_spaces_roi_violation)
{
if (_context.parking_spaces_roi_violation == null)
{
return Problem("Entity set 'SqlContext.parking_spaces_roi_violation' is null.");
}
parking_spaces_roi_violation.data_create_time= DateTime.Now;
_context.parking_spaces_roi_violation.Add(parking_spaces_roi_violation);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (Parking_spaces_roi_violationExists(parking_spaces_roi_violation.parking_spaces_name))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtAction("GetParking_spaces_roi_violation", new { id = parking_spaces_roi_violation.parking_spaces_name }, parking_spaces_roi_violation);
}
#endregion
private bool Parking_spaces_roi_violationExists(string id)
{
return (_context.parking_spaces_roi_violation?.Any(e => e.parking_spaces_name == id)).GetValueOrDefault();
}
}
}