From ae561f8311835058cb5401ff162edeab915b65ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=97=D0=B5=D0=BB?= =?UTF-8?q?=D1=82=D1=8B=D0=BD=D1=8C?= Date: Wed, 6 May 2026 00:36:49 +0900 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D0=B5=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B5=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=BD=D0=B0=20=D0=B0=D1=81?= =?UTF-8?q?=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CartriX.Api/Controllers/PrinterController.cs | 12 ++++-------- CartriX.Shared/Mappers/PrinterMap.cs | 12 +++++------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/CartriX.Api/Controllers/PrinterController.cs b/CartriX.Api/Controllers/PrinterController.cs index 6e1387a..de6da80 100644 --- a/CartriX.Api/Controllers/PrinterController.cs +++ b/CartriX.Api/Controllers/PrinterController.cs @@ -2,7 +2,6 @@ using CartriX.Shared.Classes; using CartriX.Shared.DTOs.Printer; using CartriX.Shared.Mappers; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace CartriX.Api.Controllers @@ -18,22 +17,19 @@ namespace CartriX.Api.Controllers _context = context; _printerNetworkService = printerNetworkService; } - - [HttpGet("{IpAddressOrHost}")] public async Task GetInformationFromSnmp(string IpAddressOrHost) { var value = await _printerNetworkService.GetPrinterListParametersAsync(IpAddressOrHost); - return Ok(value); } [HttpPost] - public IActionResult AddPrinter([FromBody] CreatePrinterRequestDto requestDto) + public async Task AddPrinter([FromBody] CreatePrinterRequestDto requestDto) { - var printerModel = requestDto.ToPrinterModel(_context); + var printerModel = requestDto.ToPrinterModelAsync(_context); - _context.Printers.Add(printerModel); - _context.SaveChanges(); + await _context.Printers.AddAsync(printerModel); + await _context.SaveChangesAsync(); return Ok(printerModel.ToDto()); } diff --git a/CartriX.Shared/Mappers/PrinterMap.cs b/CartriX.Shared/Mappers/PrinterMap.cs index 4ea90b5..712a506 100644 --- a/CartriX.Shared/Mappers/PrinterMap.cs +++ b/CartriX.Shared/Mappers/PrinterMap.cs @@ -1,9 +1,7 @@ using CartriX.Shared.Classes; using CartriX.Shared.DTOs.Printer; using CartriX.Shared.Models; -using System; -using System.Collections.Generic; -using System.Text; +using Microsoft.EntityFrameworkCore; namespace CartriX.Shared.Mappers { @@ -16,7 +14,7 @@ namespace CartriX.Shared.Mappers Name = printer.hostname }; } - public static PrinterDto ToDto(this Printer printer) + public static async Task ToDtoAsync(this Printer printer) { return new() { @@ -26,10 +24,10 @@ namespace CartriX.Shared.Mappers modelName = printer.model.name }; } - public static Printer ToPrinterModel(this CreatePrinterRequestDto requestDto, AppDbContext context) + public static async Task ToPrinterModelAsync(this CreatePrinterRequestDto requestDto, AppDbContext context) { - Location location = (context.Locations.Any(l => l.name == requestDto.locationValue)) ? context.Locations.First(l => l.name == requestDto.locationValue) : new() { name = requestDto.locationValue }; - PrinterModel model = (context.PrinterModels.Any(m => m.name == requestDto.modelName)) ? context.PrinterModels.First(p => p.name == requestDto.modelName) : new() { name = requestDto.modelName }; + Location location = (await context.Locations.AnyAsync(l => l.name == requestDto.locationValue)) ? await context.Locations.FirstAsync(l => l.name == requestDto.locationValue) : new() { name = requestDto.locationValue }; + PrinterModel model = (await context.PrinterModels.AnyAsync(m => m.name == requestDto.modelName)) ? await context.PrinterModels.FirstAsync(p => p.name == requestDto.modelName) : new() { name = requestDto.modelName }; return new() {