Parking_space_WEBAPI/WebApi_data_value/Controllers/Yuntech_camController.cs
2024-02-14 22:08:27 +08:00

141 lines
3.9 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 WebApi_data_value.Models;
using WebApi_data_value.Authorization;
using WebApi_data_value.Services;
namespace WebApi_data_value.Controllers
{
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class Yuntech_camController : ControllerBase
{
private readonly SqlContext _context;
public Yuntech_camController(SqlContext context)
{
_context = context;
}
// GET: api/Yuntech_cam
[HttpGet]
public async Task<ActionResult<IEnumerable<Yuntech_cam>>> Getyuntech_cam()
{
if (_context.yuntech_cam == null)
{
return NotFound();
}
return await _context.yuntech_cam.ToListAsync();
}
// GET: api/Yuntech_cam/5
[HttpGet("{id}")]
public async Task<ActionResult<Yuntech_cam>> GetYuntech_cam(string id)
{
if (_context.yuntech_cam == null)
{
return NotFound();
}
var yuntech_cam = await _context.yuntech_cam.FindAsync(id);
if (yuntech_cam == null)
{
return NotFound();
}
return yuntech_cam;
}
// PUT: api/Yuntech_cam/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutYuntech_cam(string id, Yuntech_cam yuntech_cam)
{
if (id != yuntech_cam.ip)
{
return BadRequest();
}
_context.Entry(yuntech_cam).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!Yuntech_camExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Yuntech_cam
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Yuntech_cam>> PostYuntech_cam(Yuntech_cam yuntech_cam)
{
if (_context.yuntech_cam == null)
{
return Problem("Entity set 'SqlContext.yuntech_cam' is null.");
}
_context.yuntech_cam.Add(yuntech_cam);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (Yuntech_camExists(yuntech_cam.ip))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtAction("GetYuntech_cam", new { id = yuntech_cam.ip }, yuntech_cam);
}
// DELETE: api/Yuntech_cam/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteYuntech_cam(string id)
{
if (_context.yuntech_cam == null)
{
return NotFound();
}
var yuntech_cam = await _context.yuntech_cam.FindAsync(id);
if (yuntech_cam == null)
{
return NotFound();
}
_context.yuntech_cam.Remove(yuntech_cam);
await _context.SaveChangesAsync();
return NoContent();
}
private bool Yuntech_camExists(string id)
{
return (_context.yuntech_cam?.Any(e => e.ip == id)).GetValueOrDefault();
}
}
}