mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 12:30:55 +00:00
Был сделан запрос POST для создание записи о принтере
This commit is contained in:
1 parent
7a0e7e0801
commit
02160f451f
43 files changed
+1044
-634
No files matched your search
@@ -1,51 +1,41 @@
|
||||
using CartriX.Api.Services;
|
||||
using CartriX.Api.Services;
|
||||
using CartriX.Shared.Classes;
|
||||
using CartriX.Shared.DTOs.Printer;
|
||||
using CartriX.Shared.Models;
|
||||
using CartriX.Shared.Mappers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CartriX.Api.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[Route("api/Printer")]
|
||||
public class PrinterController : ControllerBase
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
private readonly PrinterNetworkService _printerNetworkService;
|
||||
|
||||
public PrinterController(AppDbContext context, PrinterNetworkService printerNetworkService)
|
||||
{
|
||||
_context = context;
|
||||
_printerNetworkService = printerNetworkService;
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public ActionResult GetPrinter(int id)
|
||||
|
||||
[HttpGet("{IpAddressOrHost}")]
|
||||
public async Task<ActionResult> GetInformationFromSnmp(string IpAddressOrHost)
|
||||
{
|
||||
Printer printer = _context.Printers.Find(id)!;
|
||||
return printer == null ? NotFound() : Ok(printer);
|
||||
var value = await _printerNetworkService.GetPrinterListParametersAsync(IpAddressOrHost);
|
||||
|
||||
return Ok(value);
|
||||
}
|
||||
|
||||
[HttpGet("GetSNMP/{IpAddressOrHostname}")]
|
||||
public async Task<IActionResult> GetSNMPQueryResult(string IpAddressOrHostname)
|
||||
[HttpPost]
|
||||
public IActionResult AddPrinter([FromBody] CreatePrinterRequestDto requestDto)
|
||||
{
|
||||
try
|
||||
{
|
||||
QueryPrinterToAdd? printerData = await _printerNetworkService.GetPrinterListParametersAsync(IpAddressOrHostname);
|
||||
var printerModel = requestDto.ToPrinterModel(_context);
|
||||
|
||||
return Ok(printerData);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
return Problem(detail: ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Problem(detail: ex.Message);
|
||||
}
|
||||
_context.Printers.Add(printerModel);
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(printerModel.ToDto());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user