Files
PowderCoatingLogix/src/PowderCoating.Application/Mappings/InventoryProfile.cs
T
2026-04-23 21:38:24 -04:00

55 lines
2.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AutoMapper;
using PowderCoating.Core.Entities;
using PowderCoating.Application.DTOs.Inventory;
namespace PowderCoating.Application.Mappings;
public class InventoryProfile : Profile
{
public InventoryProfile()
{
// InventoryItem to InventoryItemDto
CreateMap<InventoryItem, InventoryItemDto>()
.ForMember(dest => dest.CategoryName,
opt => opt.MapFrom(src => src.InventoryCategory != null ? src.InventoryCategory.DisplayName : null))
.ForMember(dest => dest.PrimaryVendorName,
opt => opt.MapFrom(src => src.PrimaryVendor != null ? src.PrimaryVendor.CompanyName : null))
.ForMember(dest => dest.IsLowStock,
opt => opt.MapFrom(src => src.QuantityOnHand > 0 && src.QuantityOnHand <= src.ReorderPoint))
.ForMember(dest => dest.IsOutOfStock,
opt => opt.MapFrom(src => src.QuantityOnHand <= 0))
.ForMember(dest => dest.InventoryAccountName,
opt => opt.MapFrom(src => src.InventoryAccount != null
? $"{src.InventoryAccount.AccountNumber} {src.InventoryAccount.Name}" : null))
.ForMember(dest => dest.CogsAccountName,
opt => opt.MapFrom(src => src.CogsAccount != null
? $"{src.CogsAccount.AccountNumber} {src.CogsAccount.Name}" : null));
// CreateInventoryItemDto to InventoryItem
CreateMap<CreateInventoryItemDto, InventoryItem>()
.ForMember(dest => dest.AverageCost, opt => opt.MapFrom(src => src.UnitCost))
.ForMember(dest => dest.LastPurchasePrice, opt => opt.MapFrom(src => src.UnitCost))
.ForMember(dest => dest.InventoryAccount, opt => opt.Ignore())
.ForMember(dest => dest.CogsAccount, opt => opt.Ignore());
// UpdateInventoryItemDto to InventoryItem
CreateMap<UpdateInventoryItemDto, InventoryItem>()
.ForMember(dest => dest.InventoryAccount, opt => opt.Ignore())
.ForMember(dest => dest.CogsAccount, opt => opt.Ignore());
// InventoryItem to UpdateInventoryItemDto (needed for Edit GET action)
CreateMap<InventoryItem, UpdateInventoryItemDto>();
// InventoryItem to InventoryListDto
CreateMap<InventoryItem, InventoryListDto>()
.ForMember(dest => dest.CategoryName,
opt => opt.MapFrom(src => src.InventoryCategory != null ? src.InventoryCategory.DisplayName : null))
.ForMember(dest => dest.PrimaryVendorName,
opt => opt.MapFrom(src => src.PrimaryVendor != null ? src.PrimaryVendor.CompanyName : null))
.ForMember(dest => dest.IsLowStock,
opt => opt.MapFrom(src => src.QuantityOnHand > 0 && src.QuantityOnHand <= src.ReorderPoint))
.ForMember(dest => dest.IsOutOfStock,
opt => opt.MapFrom(src => src.QuantityOnHand <= 0));
}
}