46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using System;
|
|
using AutoMapper;
|
|
using Heroic.AutoMapper;
|
|
using InventoryTraker.Web.Core;
|
|
|
|
namespace InventoryTraker.Web.Models
|
|
{
|
|
public class InventoryViewModel : IMapFrom<Inventory>, IHaveCustomMappings
|
|
{
|
|
public int Id { get; set; }
|
|
|
|
public int InventoryTypeId { 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 DateTime AddedDate { get; set; }
|
|
|
|
public string Memo { get; set; }
|
|
|
|
public bool IsExpired => ExpirationDate < DateTime.Today;
|
|
|
|
public void CreateMappings(IMapperConfiguration configuration)
|
|
{
|
|
configuration.CreateMap<Inventory, InventoryViewModel>()
|
|
.ForMember(d => d.InventoryTypeId, opt => opt.MapFrom(s => s.InventoryType.Id))
|
|
.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.ContainerType, opt => opt.MapFrom(s => s.InventoryType.ContainerType))
|
|
.ForMember(d => d.WeightPerCase, opt => opt.MapFrom(s => s.InventoryType.WeightPerCase))
|
|
.ForMember(d => d.PricePerCase, opt => opt.MapFrom(s => s.InventoryType.PricePerCase))
|
|
.ForMember(d => d.AddedDate, opt => opt.MapFrom(s => s.AddedDate));
|
|
}
|
|
}
|
|
} |