This commit is contained in:
@@ -17,15 +17,16 @@ public class DeviceController : ControllerBase
|
||||
}
|
||||
|
||||
//=========================== GET =================================//
|
||||
#region GET
|
||||
[HttpGet("GetTypes")]
|
||||
[ProducesResponseType<List<DeviceType>>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public IActionResult GetList()
|
||||
public IActionResult GetList()// Получить лист типов устройств
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
var tps = db.DeviceTypes.ToList();
|
||||
if (tps.Count != 0)
|
||||
if (tps.Count != 0)
|
||||
return Ok(tps);
|
||||
else return NoContent();
|
||||
}
|
||||
@@ -34,7 +35,7 @@ public class DeviceController : ControllerBase
|
||||
[HttpGet("GetDeviceById")]
|
||||
[ProducesResponseType<DeviceItem>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public IActionResult GetById(int id)
|
||||
public IActionResult GetById(int id) // Получить устройство по id
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
@@ -48,20 +49,22 @@ public class DeviceController : ControllerBase
|
||||
[HttpGet("GetDevices")]
|
||||
[ProducesResponseType<DeviceItem>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public IActionResult GetAll()
|
||||
public IActionResult GetAll() // Получить все устройства
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
var d = db.Devices.ToList();
|
||||
//if (d.Count != 0)
|
||||
return Ok(d);
|
||||
return Ok(d);
|
||||
//else return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
//========================= POST ====================================//
|
||||
#region POST
|
||||
[HttpPost("AddDevice")]
|
||||
public IActionResult AddDevice(DeviceItem d)
|
||||
public IActionResult AddDevice(DeviceItem d) // Добавить одно устройство
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
@@ -72,7 +75,7 @@ public class DeviceController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPost("AddType")]
|
||||
public IActionResult AddType(DeviceType d)
|
||||
public IActionResult AddType(DeviceType d) //Добавить один тип устройства
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
@@ -80,18 +83,33 @@ public class DeviceController : ControllerBase
|
||||
db.SaveChanges();
|
||||
return Created();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
//========================= DELETE ====================================//
|
||||
#region DELETE
|
||||
[HttpDelete("DelType")]
|
||||
public IActionResult DelType(int id)
|
||||
public IActionResult DelType(int id) //Удалить тип устройства по id
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
var deldev = db.DeviceTypes.Where(u => u.Id == id).FirstOrDefault();
|
||||
db.DeviceTypes.Remove(deldev);
|
||||
var deldevtype = db.DeviceTypes.Where(u => u.Id == id).FirstOrDefault();
|
||||
db.DeviceTypes.Remove(deldevtype);
|
||||
db.SaveChanges();
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("DelDevice")]
|
||||
public IActionResult DelDevice(int id) //Удалить устройство по id
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
var deldev = db.Devices.Where(u => u.Id == id).FirstOrDefault();
|
||||
db.Devices.Remove(deldev);
|
||||
db.SaveChanges();
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Strela.Models;
|
||||
using Strela.Services;
|
||||
|
||||
namespace Strela.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class ObjectController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<ObjectController> _logger;
|
||||
|
||||
public ObjectController(ILogger<ObjectController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
//=========================== GET =================================//
|
||||
[HttpGet("GetObject")]
|
||||
[ProducesResponseType<List<ObjectItem>>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public IActionResult GetList()
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
var oi = db.ObjectItems.ToList();
|
||||
//if (oi.Count != 0)
|
||||
return Ok(oi);
|
||||
//else return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetObjectById")]
|
||||
[ProducesResponseType<ObjectItem>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public IActionResult GetById(int id)
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
var o = db.ObjectItems.Where(o => o.Id == id).FirstOrDefault();
|
||||
if (o != null)
|
||||
return Ok(o);
|
||||
else return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetObjectByName")]
|
||||
[ProducesResponseType<ObjectItem>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public IActionResult GetByName(string name)
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
var o = db.ObjectItems.Where(ob => ob.NameObject == name).FirstOrDefault();
|
||||
if (o != null)
|
||||
return Ok(o);
|
||||
else return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================= POST ====================================//
|
||||
[HttpPost("AddObject")]
|
||||
public IActionResult AddObject(ObjectItem o)
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
db.ObjectItems.Add(o);//.Where(u => u.Name == name).FirstOrDefault();
|
||||
db.SaveChanges();
|
||||
return Created();
|
||||
}
|
||||
}
|
||||
|
||||
//========================= DELETE ====================================//
|
||||
[HttpDelete("DelObject")]
|
||||
public IActionResult DelObject(int id)
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
var delobj = db.ObjectItems.Where(o => o.Id == id).FirstOrDefault();
|
||||
db.ObjectItems.Remove(delobj);
|
||||
db.SaveChanges();
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,13 @@
|
||||
public class DeviceItem
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Ip { get; set; }
|
||||
public string Mac { 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 List<DeviceItem>? ListDevices { get; set; }
|
||||
public DeviceType? DeviceType { get; set; }
|
||||
public int ConnectedToSwitchId { get; set; }
|
||||
public int ConnectedToPortOnSwitch { get; set; }
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Strela.Models
|
||||
{
|
||||
public class ObjectItem
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string NameObject { get; set; } = "Unknown";
|
||||
public string DescriptionObject { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -9,6 +9,7 @@ namespace Strela.Services
|
||||
public virtual DbSet<User> Users { get; set; }
|
||||
public virtual DbSet<DeviceItem> Devices { get; set; }
|
||||
public virtual DbSet<DeviceType> DeviceTypes { get; set; }
|
||||
public virtual DbSet<ObjectItem> ObjectItems { get; set; }
|
||||
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Models\OTD\**" />
|
||||
<Content Remove="Models\OTD\**" />
|
||||
<EmbeddedResource Remove="Models\OTD\**" />
|
||||
<None Remove="Models\OTD\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.16" />
|
||||
@@ -23,8 +30,4 @@
|
||||
<ProjectReference Include="..\lsSoft.ServiceDefaults\lsSoft.ServiceDefaults.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\OTD\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user