65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using System;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using AutoMapper;
|
|
using InventoryTraker.Web.Core;
|
|
|
|
namespace InventoryTraker.Web.Models
|
|
{
|
|
public class TransactionViewModel
|
|
{
|
|
[Required]
|
|
public int Id { get; set; }
|
|
public int InventoryId { get; set; }
|
|
|
|
public string Name { get; set; }
|
|
public int UnitsPerCase { get; set; }
|
|
public string ContainerType { get; set; }
|
|
public DateTime ExpirationDate { get; set; }
|
|
public DateTime AddedDate { get; set; }
|
|
public double WeightPerCase { get; set; }
|
|
|
|
public string TransactionType { get; set; }
|
|
|
|
public int PreviousQuantity { get; set; }
|
|
|
|
public int AddedQuantity { get; set; }
|
|
|
|
public int RemovedQuantity { get; set; }
|
|
|
|
public int CurrentQuantity { get; set; }
|
|
|
|
public DateTime TransactionDate { get; set; }
|
|
|
|
public string Memo { get; set; }
|
|
|
|
public string Destination { get; set; }
|
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
|
public class AutoMapperProfile : Profile
|
|
{
|
|
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));
|
|
}
|
|
}
|
|
}
|
|
} |