This commit is contained in:
@@ -9,28 +9,16 @@ namespace Strela.Controllers;
|
||||
[Route("api/[controller]")]
|
||||
public class DeviceController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<UserController> _logger;
|
||||
private readonly ILogger<DeviceController> _logger;
|
||||
|
||||
public DeviceController(ILogger<UserController> logger)
|
||||
public DeviceController(ILogger<DeviceController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
//=========================== GET =================================//
|
||||
#region 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("GetDeviceById")]
|
||||
[ProducesResponseType<DeviceItem>(StatusCodes.Status200OK)]
|
||||
@@ -74,32 +62,12 @@ public class DeviceController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
[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();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//========================= DELETE ====================================//
|
||||
#region DELETE
|
||||
[HttpDelete("DelType")]
|
||||
public IActionResult DelType(int id) //Удалить тип устройства по id
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
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
|
||||
{
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Strela.Models;
|
||||
using Strela.Services;
|
||||
|
||||
namespace Strela.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class TypeController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<TypeController> _logger;
|
||||
|
||||
public TypeController(ILogger<TypeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
//=========================== GET =================================//
|
||||
#region GET
|
||||
[HttpGet("GetTypes")]
|
||||
public IActionResult GetList()// Получить лист типов устройств
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
var tps = db.DeviceTypes.ToList();
|
||||
return Ok(tps);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetTypeById")]
|
||||
[ProducesResponseType<DeviceItem>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public IActionResult GetById(int id) // Получить устройство по id
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
var d = db.DeviceTypes.Where(d => d.Id == id).FirstOrDefault();
|
||||
if (d != null)
|
||||
return Ok(d);
|
||||
else return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
//========================= POST ====================================//
|
||||
#region POST
|
||||
|
||||
[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();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
//========================= DELETE ====================================//
|
||||
#region DELETE
|
||||
[HttpDelete("DelType")]
|
||||
public IActionResult DelType(int id) //Удалить тип устройства по id
|
||||
{
|
||||
using (var db = new SQLiteService())
|
||||
{
|
||||
var deldevtype = db.DeviceTypes.Where(u => u.Id == id).FirstOrDefault();
|
||||
db.DeviceTypes.Remove(deldevtype);
|
||||
db.SaveChanges();
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
public class DeviceItem
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
public string? Ip { get; set; }
|
||||
public string? Mac { get; set; }
|
||||
public string? Description { get; set; }
|
||||
@@ -11,7 +11,7 @@
|
||||
public List<DeviceItem>? ListDevices { get; set; }
|
||||
public DeviceType? DeviceType { get; set; }
|
||||
public ObjectItem? DeviceObject { get; set; }
|
||||
public int ConnectedToSwitchId { get; set; }
|
||||
public Guid ConnectedToSwitchId { get; set; }
|
||||
public int ConnectedToPortOnSwitch { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
public class DeviceType
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
public class ObjectItem
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
public string NameObject { get; set; } = "Unknown";
|
||||
public string? DescriptionObject { get; set; } = null;
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user