This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Strela.Models;
|
||||
using Strela.Services;
|
||||
|
||||
namespace Strela.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class DeviceController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<UserController> _logger;
|
||||
|
||||
public DeviceController(ILogger<UserController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
//=========================== GET =================================//
|
||||
[HttpGet("GetTypes")]
|
||||
[ProducesResponseType<List<DeviceType>>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public IActionResult GetList()
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
var tps = db.DeviceTypes.ToList();
|
||||
if (tps.Count != 0)
|
||||
return Ok(tps);
|
||||
else return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetDevice")]
|
||||
[ProducesResponseType<DeviceItem>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public IActionResult GetById(int id)
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
var d = db.Devices.Where(d => d.Id == id).FirstOrDefault();
|
||||
if (d != null)
|
||||
return Ok(d);
|
||||
else return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
//========================= POST ====================================//
|
||||
[HttpPost("AddDevice")]
|
||||
public IActionResult AddDevice(DeviceItem d)
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
db.Devices.Add(d);//.Where(u => u.Name == name).FirstOrDefault();
|
||||
db.SaveChanges();
|
||||
return Created();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("AddType")]
|
||||
public IActionResult AddType(DeviceType d)
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
db.DeviceTypes.Add(d);//.Where(u => u.Name == name).FirstOrDefault();
|
||||
db.SaveChanges();
|
||||
return Created();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace Strela.Models
|
||||
{
|
||||
public class DeviceItem
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Ip { get; set; }
|
||||
public string Mac { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Location { get; set; }
|
||||
public List<DeviceItem> Devises { get; set; }
|
||||
public DeviceType DeviceType { get; set; }
|
||||
public int ConnectedToSwitchId { get; set; }
|
||||
public int ConnectedToPortOnSwitch { get; set; }
|
||||
|
||||
//public DeviceItem(int type, string ip, string mac, string location)
|
||||
//{
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
//Unknown = 0,
|
||||
//SwitchCore = 1,
|
||||
//SwitchAccess = 2,
|
||||
//Camera = 3,
|
||||
//Server = 4,
|
||||
//WorkStation = 5,
|
||||
//PDU_AVR = 6,
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Strela.Models
|
||||
{
|
||||
public class DeviceType
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -7,7 +7,9 @@ namespace Strela.Services
|
||||
{
|
||||
public SQLiteService() => Database.EnsureCreated();
|
||||
public virtual DbSet<User> Users { get; set; }
|
||||
|
||||
public virtual DbSet<DeviceItem> Devices { get; set; }
|
||||
public virtual DbSet<DeviceType> DeviceTypes { get; set; }
|
||||
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
|
||||
@@ -23,4 +23,8 @@
|
||||
<ProjectReference Include="..\lsSoft.ServiceDefaults\lsSoft.ServiceDefaults.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\OTD\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user