Files
CartriX/CartriX.Shared/Mappers/PrinterMap.cs
T

51 lines
2.0 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,
printTypeId = int.Parse(requestDto.typePrintId),
oidForQueryCountPrintedAllTime = requestDto.oidForQueryCountPrintedAllTime,
countPrintedAllTime = int.Parse(requestDto.countPrintedAllTime)
};
}
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
};
}
}
}