mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-06 13:00: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,8 +1,6 @@
|
||||
using CartriX.Shared.DTOs.Location;
|
||||
using CartriX.Shared.DTOs.Printer;
|
||||
using CartriX.Shared.Classes;
|
||||
using CartriX.Shared.Mappers;
|
||||
using CartriX.Shared.Models;
|
||||
using CartriX.Shared.Patterns;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -18,19 +16,23 @@ namespace CartriX.Api.Controllers
|
||||
_context = context;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("List")]
|
||||
public IActionResult GetListLocations()
|
||||
{
|
||||
var locations = _context.Locations.Include(l => l.Printers).ToList();
|
||||
var locations = _context.Locations.ToList().Select(l => l.OnlyName());
|
||||
return Ok(locations);
|
||||
}
|
||||
[HttpGet("{Id}")]
|
||||
public IActionResult GetLocationListPrinters(int id)
|
||||
{
|
||||
var printers = _context.Printers.Where(p => p.locationId == id).Select(p => p.OnlyName());
|
||||
|
||||
var result = locations.Select(l => new PrintersAndLocations
|
||||
if (!printers.Any())
|
||||
{
|
||||
Name = l.Name,
|
||||
Printers = l.Printers
|
||||
}).ToList();
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return Ok(result);
|
||||
return Ok(printers);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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