Добавил добавление объекта
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 12s

This commit is contained in:
2026-07-03 18:35:09 +03:00
parent 5b14466d24
commit fd6506af7b
16 changed files with 336 additions and 54 deletions
+30 -12
View File
@@ -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
}