Update automapper
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using AutoMapper;
|
||||
using Heroic.AutoMapper;
|
||||
using InventoryTraker.Web.Core;
|
||||
|
||||
namespace InventoryTraker.Web.Models
|
||||
{
|
||||
public class TransactionViewModel : IMapFrom<Transaction>, IHaveCustomMappings
|
||||
public class TransactionViewModel
|
||||
{
|
||||
[Required]
|
||||
public int Id { get; set; }
|
||||
@@ -37,27 +36,30 @@ namespace InventoryTraker.Web.Models
|
||||
|
||||
public DateTime Timestamp { get; set; }
|
||||
|
||||
public void CreateMappings(IMapperConfiguration configuration)
|
||||
public class AutoMapperProfile : Profile
|
||||
{
|
||||
configuration.CreateMap<Transaction, TransactionViewModel>()
|
||||
.ForMember(d => d.InventoryId,
|
||||
opt => opt.MapFrom(s => s.Inventory.Id))
|
||||
.ForMember(d => d.Name,
|
||||
opt => opt.MapFrom(s => s.Inventory.InventoryType.Name))
|
||||
.ForMember(d => d.ExpirationDate,
|
||||
opt => opt.MapFrom(s => s.Inventory.ExpirationDate))
|
||||
.ForMember(d => d.AddedDate,
|
||||
opt => opt.MapFrom(s => s.Inventory.AddedDate))
|
||||
.ForMember(d => d.UnitsPerCase,
|
||||
opt => opt.MapFrom(s => s.Inventory.InventoryType.UnitsPerCase))
|
||||
.ForMember(d => d.ContainerType,
|
||||
opt => opt.MapFrom(s => s.Inventory.InventoryType.ContainerType))
|
||||
.ForMember(d => d.WeightPerCase,
|
||||
opt => opt.MapFrom(s => s.Inventory.InventoryType.WeightPerCase))
|
||||
.ForMember(d => d.TransactionType,
|
||||
opt => opt.MapFrom(s => s.TransactionType.ToString()))
|
||||
.ForMember(d => d.PreviousQuantity,
|
||||
opt => opt.MapFrom(s => s.CurrentQuantity - s.AddedQuantity + s.RemovedQuantity));
|
||||
public AutoMapperProfile()
|
||||
{
|
||||
CreateMap<Transaction, TransactionViewModel>()
|
||||
.ForMember(d => d.InventoryId,
|
||||
opt => opt.MapFrom(s => s.Inventory.Id))
|
||||
.ForMember(d => d.Name,
|
||||
opt => opt.MapFrom(s => s.Inventory.InventoryType.Name))
|
||||
.ForMember(d => d.ExpirationDate,
|
||||
opt => opt.MapFrom(s => s.Inventory.ExpirationDate))
|
||||
.ForMember(d => d.AddedDate,
|
||||
opt => opt.MapFrom(s => s.Inventory.AddedDate))
|
||||
.ForMember(d => d.UnitsPerCase,
|
||||
opt => opt.MapFrom(s => s.Inventory.InventoryType.UnitsPerCase))
|
||||
.ForMember(d => d.ContainerType,
|
||||
opt => opt.MapFrom(s => s.Inventory.InventoryType.ContainerType))
|
||||
.ForMember(d => d.WeightPerCase,
|
||||
opt => opt.MapFrom(s => s.Inventory.InventoryType.WeightPerCase))
|
||||
.ForMember(d => d.TransactionType,
|
||||
opt => opt.MapFrom(s => s.TransactionType.ToString()))
|
||||
.ForMember(d => d.PreviousQuantity,
|
||||
opt => opt.MapFrom(s => s.CurrentQuantity - s.AddedQuantity + s.RemovedQuantity));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user