using System; using AutoMapper; using Heroic.AutoMapper; using InventoryTraker.Web.Core; namespace InventoryTraker.Web.Models { public class InventoryViewModel : IMapFrom, IHaveCustomMappings { public int Id { get; set; } public string Name { get; set; } public int UnitsPerCase { get; set; } public string ContainerType { get; set; } public double WeightPerCase { get; set; } public decimal PricePerCase { get; set; } public int Quantity { get; set; } public DateTime ExpirationDate { get; set; } public void CreateMappings(IMapperConfiguration configuration) { configuration.CreateMap() .ForMember(d => d.Name, opt => opt.MapFrom(s => s.InventoryType.Name)) .ForMember(d => d.UnitsPerCase, opt => opt.MapFrom(s => s.InventoryType.UnitsPerCase)) .ForMember(d => d.WeightPerCase, opt => opt.MapFrom(s => s.InventoryType.WeightPerCase)) .ForMember(d => d.PricePerCase, opt => opt.MapFrom(s => s.InventoryType.PricePerCase)); } } }