using CartriX.Shared.Classes; using CartriX.Shared.DTOs.Printer; using CartriX.Shared.Models; using System; using System.Collections.Generic; using System.Text; namespace CartriX.Shared.Mappers { public static class PrinterMap { public static PrinterName OnlyName(this Printer printer) { return new() { Name = printer.hostname }; } public static PrinterDto ToDto(this Printer printer) { return new() { hostname = printer.hostname, ipAddress = printer.ipAddress, locationName = printer.location.name, modelName = printer.model.name }; } public static Printer ToPrinterModel(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 }; return new() { hostname = requestDto.hostname, ipAddress = requestDto.ipAddress, location = location, model = model }; } } }