122 lines
3.5 KiB
C#
122 lines
3.5 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using CommonEntity;
|
|||
|
|
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
using Microsoft.AspNetCore.Http;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
using Microsoft.EntityFrameworkCore;
|
|||
|
|
using MySQLAccess.PGModels;
|
|||
|
|
|
|||
|
|
namespace IotManager.Controllers
|
|||
|
|
{
|
|||
|
|
[Route("api/[controller]/[action]")]
|
|||
|
|
[ApiController]
|
|||
|
|
public class TcpCloseDataController : ControllerBase
|
|||
|
|
{
|
|||
|
|
private readonly PostgresContext _context;
|
|||
|
|
|
|||
|
|
public TcpCloseDataController(PostgresContext context)
|
|||
|
|
{
|
|||
|
|
_context = context;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// GET: api/TcpCloseData
|
|||
|
|
[Authorize()]
|
|||
|
|
[HttpGet]
|
|||
|
|
public async Task<ReturnInfo> GetTcpCloseData(int page_size, int page_index, string ip, int port)
|
|||
|
|
{
|
|||
|
|
ReturnInfo r = new ReturnInfo();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
r.isok = true;
|
|||
|
|
r.response = await _context.TcpCloseData.Where(A => A.WwwIp.Equals(ip) && A.WwwPort == port).Skip((page_index - 1) * page_size).Take(page_size).ToListAsync();
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
r.isok = false;
|
|||
|
|
r.message = ex.Message;
|
|||
|
|
}
|
|||
|
|
return r;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// GET: api/TcpCloseData/5
|
|||
|
|
[HttpGet("{id}")]
|
|||
|
|
public async Task<ActionResult<TcpCloseDatum>> GetTcpCloseDatum(long id)
|
|||
|
|
{
|
|||
|
|
var tcpCloseDatum = await _context.TcpCloseData.FindAsync(id);
|
|||
|
|
|
|||
|
|
if (tcpCloseDatum == null)
|
|||
|
|
{
|
|||
|
|
return NotFound();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return tcpCloseDatum;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// PUT: api/TcpCloseData/5
|
|||
|
|
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|||
|
|
[HttpPut("{id}")]
|
|||
|
|
public async Task<IActionResult> PutTcpCloseDatum(long id, TcpCloseDatum tcpCloseDatum)
|
|||
|
|
{
|
|||
|
|
if (id != tcpCloseDatum.Id)
|
|||
|
|
{
|
|||
|
|
return BadRequest();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_context.Entry(tcpCloseDatum).State = EntityState.Modified;
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
await _context.SaveChangesAsync();
|
|||
|
|
}
|
|||
|
|
catch (DbUpdateConcurrencyException)
|
|||
|
|
{
|
|||
|
|
if (!TcpCloseDatumExists(id))
|
|||
|
|
{
|
|||
|
|
return NotFound();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
throw;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return NoContent();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// POST: api/TcpCloseData
|
|||
|
|
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|||
|
|
[HttpPost]
|
|||
|
|
public async Task<ActionResult<TcpCloseDatum>> PostTcpCloseDatum(TcpCloseDatum tcpCloseDatum)
|
|||
|
|
{
|
|||
|
|
_context.TcpCloseData.Add(tcpCloseDatum);
|
|||
|
|
await _context.SaveChangesAsync();
|
|||
|
|
|
|||
|
|
return CreatedAtAction("GetTcpCloseDatum", new { id = tcpCloseDatum.Id }, tcpCloseDatum);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DELETE: api/TcpCloseData/5
|
|||
|
|
[HttpDelete("{id}")]
|
|||
|
|
public async Task<IActionResult> DeleteTcpCloseDatum(long id)
|
|||
|
|
{
|
|||
|
|
var tcpCloseDatum = await _context.TcpCloseData.FindAsync(id);
|
|||
|
|
if (tcpCloseDatum == null)
|
|||
|
|
{
|
|||
|
|
return NotFound();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_context.TcpCloseData.Remove(tcpCloseDatum);
|
|||
|
|
await _context.SaveChangesAsync();
|
|||
|
|
|
|||
|
|
return NoContent();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private bool TcpCloseDatumExists(long id)
|
|||
|
|
{
|
|||
|
|
return _context.TcpCloseData.Any(e => e.Id == id);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|