mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-06 04:50:55 +00:00
48 lines
1.8 KiB
C#
48 lines
1.8 KiB
C#
using CartriX.Shared.Classes;
|
|
using CartriX.Shared.DTOs.Printer;
|
|
using CartriX.Shared.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace CartriX.Shared.Mappers
|
|
{
|
|
public static class PrinterMap
|
|
{
|
|
public static PrinterDto ToDto(this Printer printer)
|
|
{
|
|
return new()
|
|
{
|
|
name = printer.name,
|
|
hostname = printer.hostname,
|
|
ipAddress = printer.ipAddress,
|
|
location = printer.location,
|
|
model = printer.model
|
|
};
|
|
}
|
|
public static async Task<Printer> ToPrinterModelAsync(this CreatePrinterRequestDto requestDto, AppDbContext context)
|
|
{
|
|
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()
|
|
{
|
|
name = requestDto.name,
|
|
hostname = requestDto.hostname,
|
|
ipAddress = requestDto.ipAddress,
|
|
location = location,
|
|
model = model
|
|
};
|
|
}
|
|
public static QueryPrinterFromLocationDto ToQueryPrinterFromLocationDto(this Printer printer)
|
|
{
|
|
return new()
|
|
{
|
|
id = printer.id,
|
|
name = printer.name,
|
|
hostname = printer.hostname,
|
|
ipAddress = printer.ipAddress,
|
|
modelName = printer.model.name
|
|
};
|
|
}
|
|
}
|
|
}
|