mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 20:40:55 +00:00
42 lines
1.5 KiB
C#
42 lines
1.5 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 PrinterName OnlyName(this Printer printer)
|
|
{
|
|
return new()
|
|
{
|
|
Name = printer.hostname
|
|
};
|
|
}
|
|
public static async Task<PrinterDto> ToDtoAsync(this Printer printer)
|
|
{
|
|
return new()
|
|
{
|
|
hostname = printer.hostname,
|
|
ipAddress = printer.ipAddress,
|
|
locationName = printer.location.name,
|
|
modelName = printer.model.name
|
|
};
|
|
}
|
|
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()
|
|
{
|
|
hostname = requestDto.hostname,
|
|
ipAddress = requestDto.ipAddress,
|
|
location = location,
|
|
model = model
|
|
};
|
|
}
|
|
}
|
|
}
|