Update automapper
This commit is contained in:
@@ -6,14 +6,13 @@ using ClosedXML.Excel;
|
||||
using CsvHelper;
|
||||
using CsvHelper.Configuration;
|
||||
using CsvHelper.Excel;
|
||||
using Heroic.AutoMapper;
|
||||
using InventoryTraker.Web.Models;
|
||||
|
||||
namespace InventoryTraker.Web.Utilities
|
||||
{
|
||||
public class DistributionReportWriter
|
||||
{
|
||||
public class DistributionReportExportItem : IMapFrom<TransactionViewModel>, IHaveCustomMappings
|
||||
public class DistributionReportExportItem
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string UnitsPerCaseContainerType { get; set; }
|
||||
@@ -22,18 +21,21 @@ namespace InventoryTraker.Web.Utilities
|
||||
public string UnitQuantity { get; set; }
|
||||
public string Weight { get; set; }
|
||||
|
||||
public void CreateMappings(IMapperConfiguration configuration)
|
||||
public class AutoMapperProfile : Profile
|
||||
{
|
||||
configuration.CreateMap<TransactionViewModel, DistributionReportExportItem>()
|
||||
public AutoMapperProfile()
|
||||
{
|
||||
CreateMap<TransactionViewModel, DistributionReportExportItem>()
|
||||
.ForMember(d => d.Name, opt => opt.MapFrom(i => i.Name))
|
||||
.ForMember(d => d.UnitsPerCaseContainerType,
|
||||
opt => opt.MapFrom(i => $"{i.UnitsPerCase} / {i.ContainerType}"))
|
||||
.ForMember(d => d.ExpirationDate,
|
||||
opt => opt.MapFrom(i => i.ExpirationDate.ToShortDateString()))
|
||||
.ForMember(d => d.UnitQuantity,
|
||||
opt => opt.MapFrom(i => i.RemovedQuantity*i.UnitsPerCase))
|
||||
opt => opt.MapFrom(i => i.RemovedQuantity * i.UnitsPerCase))
|
||||
.ForMember(d => d.Weight,
|
||||
opt => opt.MapFrom(i => $"{i.WeightPerCase*i.RemovedQuantity:0} lbs"));
|
||||
opt => opt.MapFrom(i => $"{i.WeightPerCase * i.RemovedQuantity:0} lbs"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +52,13 @@ namespace InventoryTraker.Web.Utilities
|
||||
}
|
||||
}
|
||||
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public DistributionReportWriter(IMapper mapper)
|
||||
{
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public byte[] Write(IEnumerable<DistributionReport> reports)
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
@@ -75,7 +84,7 @@ namespace InventoryTraker.Web.Utilities
|
||||
writer.WriteField(report.Date.ToShortDateString());
|
||||
writer.NextRecord();
|
||||
var items =
|
||||
Mapper.Map<IEnumerable<TransactionViewModel>, IEnumerable<DistributionReportExportItem>>
|
||||
_mapper.Map<IEnumerable<TransactionViewModel>, IEnumerable<DistributionReportExportItem>>
|
||||
(report.Transactions)
|
||||
.OrderBy(i => i.Name);
|
||||
writer.WriteRecords(items);
|
||||
|
||||
Reference in New Issue
Block a user