Update automapper
This commit is contained in:
@@ -1,20 +0,0 @@
|
|||||||
using Heroic.AutoMapper;
|
|
||||||
using InventoryTraker.Web.Tests.Utilities;
|
|
||||||
|
|
||||||
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(InventoryTraker.Web.Tests.AutoMapperConfig), "Configure")]
|
|
||||||
namespace InventoryTraker.Web.Tests
|
|
||||||
{
|
|
||||||
public static class AutoMapperConfig
|
|
||||||
{
|
|
||||||
public static void Configure()
|
|
||||||
{
|
|
||||||
//NOTE: By default, the current project and all referenced projects will be scanned.
|
|
||||||
// You can customize this by passing in a lambda to filter the assemblies by name,
|
|
||||||
// like so:
|
|
||||||
//HeroicAutoMapperConfigurator.LoadMapsFromCallerAndReferencedAssemblies(x => x.Name.StartsWith("YourPrefix"));
|
|
||||||
//HeroicAutoMapperConfigurator.LoadMapsFromCallerAndReferencedAssemblies();
|
|
||||||
//If you run into issues with the maps not being located at runtime, try using this method instead:
|
|
||||||
HeroicAutoMapperConfigurator.LoadMapsFromAssemblyContainingTypeAndReferencedAssemblies<MovementReportWriterTests>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
using Heroic.AutoMapper;
|
using NUnit.Framework;
|
||||||
using InventoryTraker.Web.Core;
|
|
||||||
using NUnit.Framework;
|
|
||||||
|
|
||||||
namespace InventoryTraker.Web.Tests
|
namespace InventoryTraker.Web.Tests
|
||||||
{
|
{
|
||||||
@@ -10,7 +8,7 @@ namespace InventoryTraker.Web.Tests
|
|||||||
[OneTimeSetUp]
|
[OneTimeSetUp]
|
||||||
public void S()
|
public void S()
|
||||||
{
|
{
|
||||||
HeroicAutoMapperConfigurator.LoadMapsFromAssemblyContainingTypeAndReferencedAssemblies<Inventory>();
|
AutoMapperConfig.Configure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,8 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="AutoMapper, Version=4.2.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
|
<Reference Include="AutoMapper, Version=5.1.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\AutoMapper.4.2.0\lib\net45\AutoMapper.dll</HintPath>
|
<HintPath>..\packages\AutoMapper.5.1.1\lib\net45\AutoMapper.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Heroic.AutoMapper, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="Heroic.AutoMapper, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
@@ -42,8 +42,8 @@
|
|||||||
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
|
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="nunit.framework, Version=3.4.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
<Reference Include="nunit.framework, Version=3.4.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll</HintPath>
|
<HintPath>..\packages\NUnit.3.4.0\lib\net45\nunit.framework.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
@@ -60,7 +60,6 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="App_Start\AutoMapperConfig.cs" />
|
|
||||||
<Compile Include="Models\InventoryAddForm.cs" />
|
<Compile Include="Models\InventoryAddForm.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="App_Start\Setup.cs" />
|
<Compile Include="App_Start\Setup.cs" />
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ namespace InventoryTraker.Web.Tests.Models
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class InventoryAddFormTests
|
public class InventoryAddFormTests
|
||||||
{
|
{
|
||||||
|
private IMapper _mapper;
|
||||||
|
|
||||||
[OneTimeSetUp]
|
[OneTimeSetUp]
|
||||||
public void StartUp()
|
public void StartUp()
|
||||||
{
|
{
|
||||||
HeroicAutoMapperConfigurator.LoadMapsFromAssemblyContainingTypeAndReferencedAssemblies<Inventory>();
|
_mapper = AutoMapperConfig.Config.CreateMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -28,7 +30,7 @@ namespace InventoryTraker.Web.Tests.Models
|
|||||||
Quantity = 32
|
Quantity = 32
|
||||||
};
|
};
|
||||||
|
|
||||||
var inventory = Mapper.Map<Inventory>(form);
|
var inventory = _mapper.Map<Inventory>(form);
|
||||||
|
|
||||||
Assert.That(inventory.AddedDate, Is.EqualTo(form.AddedDate));
|
Assert.That(inventory.AddedDate, Is.EqualTo(form.AddedDate));
|
||||||
Assert.That(inventory.ExpirationDate, Is.EqualTo(form.ExpirationDate));
|
Assert.That(inventory.ExpirationDate, Is.EqualTo(form.ExpirationDate));
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Heroic.AutoMapper;
|
using AutoMapper;
|
||||||
using InventoryTraker.Web.Core;
|
|
||||||
using InventoryTraker.Web.Models;
|
using InventoryTraker.Web.Models;
|
||||||
using InventoryTraker.Web.Utilities;
|
using InventoryTraker.Web.Utilities;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@@ -11,6 +10,14 @@ namespace InventoryTraker.Web.Tests.Utilities
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class DistributionReportWriterTests
|
public class DistributionReportWriterTests
|
||||||
{
|
{
|
||||||
|
private IMapper _mapper;
|
||||||
|
|
||||||
|
[OneTimeSetUp]
|
||||||
|
public void StartUp()
|
||||||
|
{
|
||||||
|
_mapper = AutoMapperConfig.Config.CreateMapper();
|
||||||
|
}
|
||||||
|
|
||||||
private readonly DistributionReport[] _distributionReports =
|
private readonly DistributionReport[] _distributionReports =
|
||||||
{
|
{
|
||||||
new DistributionReport
|
new DistributionReport
|
||||||
@@ -54,7 +61,7 @@ namespace InventoryTraker.Web.Tests.Utilities
|
|||||||
(var outputFile
|
(var outputFile
|
||||||
= new StreamWriter(Path.Combine(@"c:\temp", "DistributionReport.xlsx")))
|
= new StreamWriter(Path.Combine(@"c:\temp", "DistributionReport.xlsx")))
|
||||||
{
|
{
|
||||||
var writer = new DistributionReportWriter();
|
var writer = new DistributionReportWriter(_mapper);
|
||||||
writer.WriteStream(_distributionReports, outputFile.BaseStream);
|
writer.WriteStream(_distributionReports, outputFile.BaseStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Heroic.AutoMapper;
|
|
||||||
using InventoryTraker.Web.Core;
|
|
||||||
using InventoryTraker.Web.Models;
|
using InventoryTraker.Web.Models;
|
||||||
using InventoryTraker.Web.Utilities;
|
using InventoryTraker.Web.Utilities;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Heroic.AutoMapper;
|
using AutoMapper;
|
||||||
using InventoryTraker.Web.Core;
|
|
||||||
using InventoryTraker.Web.Models;
|
using InventoryTraker.Web.Models;
|
||||||
using InventoryTraker.Web.Utilities;
|
using InventoryTraker.Web.Utilities;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@@ -11,6 +10,14 @@ namespace InventoryTraker.Web.Tests.Utilities
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class MovementReportWriterTests
|
public class MovementReportWriterTests
|
||||||
{
|
{
|
||||||
|
private IMapper _mapper;
|
||||||
|
|
||||||
|
[OneTimeSetUp]
|
||||||
|
public void StartUp()
|
||||||
|
{
|
||||||
|
_mapper = AutoMapperConfig.Config.CreateMapper();
|
||||||
|
}
|
||||||
|
|
||||||
private readonly MovementReport _movementReport
|
private readonly MovementReport _movementReport
|
||||||
= new MovementReport
|
= new MovementReport
|
||||||
{
|
{
|
||||||
@@ -61,7 +68,7 @@ namespace InventoryTraker.Web.Tests.Utilities
|
|||||||
(var outputFile
|
(var outputFile
|
||||||
= new StreamWriter(Path.Combine(@"c:\temp", "MovementReport.xlsx")))
|
= new StreamWriter(Path.Combine(@"c:\temp", "MovementReport.xlsx")))
|
||||||
{
|
{
|
||||||
var writer = new MovementReportWriter();
|
var writer = new MovementReportWriter(_mapper);
|
||||||
writer.WriteStream(_movementReport, outputFile.BaseStream);
|
writer.WriteStream(_movementReport, outputFile.BaseStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,10 @@
|
|||||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-5.1.1.0" newVersion="5.1.1.0" />
|
||||||
|
</dependentAssembly>
|
||||||
</assemblyBinding>
|
</assemblyBinding>
|
||||||
</runtime>
|
</runtime>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="AutoMapper" version="4.2.0" targetFramework="net452" />
|
<package id="AutoMapper" version="5.1.1" targetFramework="net452" />
|
||||||
<package id="Heroic.AutoMapper" version="2.0.0" targetFramework="net452" />
|
|
||||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
|
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
|
||||||
<package id="NUnit" version="3.4.1" targetFramework="net452" />
|
<package id="NUnit" version="3.4.0" targetFramework="net452" />
|
||||||
<package id="WebActivatorEx" version="2.1.0" targetFramework="net452" />
|
<package id="WebActivatorEx" version="2.1.0" targetFramework="net452" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -1,21 +1,18 @@
|
|||||||
using Heroic.AutoMapper;
|
using AutoMapper;
|
||||||
using InventoryTraker.Web;
|
using InventoryTraker.Web;
|
||||||
using InventoryTraker.Web.Controllers;
|
|
||||||
|
|
||||||
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(AutoMapperConfig), "Configure")]
|
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(AutoMapperConfig), "Configure")]
|
||||||
namespace InventoryTraker.Web
|
namespace InventoryTraker.Web
|
||||||
{
|
{
|
||||||
public static class AutoMapperConfig
|
public static class AutoMapperConfig
|
||||||
{
|
{
|
||||||
|
public static MapperConfiguration Config { get; private set; }
|
||||||
|
|
||||||
public static void Configure()
|
public static void Configure()
|
||||||
{
|
{
|
||||||
//NOTE: By default, the current project and all referenced projects will be scanned.
|
Config = new MapperConfiguration(cfg =>
|
||||||
// You can customize this by passing in a lambda to filter the assemblies by name,
|
cfg.AddProfiles(typeof(Controllers.UserController))
|
||||||
// like so:
|
);
|
||||||
//HeroicAutoMapperConfigurator.LoadMapsFromCallerAndReferencedAssemblies(x => x.Name.StartsWith("YourPrefix"));
|
|
||||||
//HeroicAutoMapperConfigurator.LoadMapsFromCallerAndReferencedAssemblies();
|
|
||||||
//If you run into issues with the maps not being located at runtime, try using this method instead:
|
|
||||||
HeroicAutoMapperConfigurator.LoadMapsFromAssemblyContainingTypeAndReferencedAssemblies<ControllerBase>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,12 +3,12 @@ using System.Web;
|
|||||||
using Heroic.Web.IoC;
|
using Heroic.Web.IoC;
|
||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using AutoMapper;
|
||||||
using InventoryTraker.Web.Core;
|
using InventoryTraker.Web.Core;
|
||||||
using InventoryTraker.Web.Data;
|
using InventoryTraker.Web.Data;
|
||||||
using Microsoft.AspNet.Identity;
|
using Microsoft.AspNet.Identity;
|
||||||
using Microsoft.AspNet.Identity.EntityFramework;
|
using Microsoft.AspNet.Identity.EntityFramework;
|
||||||
using Microsoft.Owin.Security;
|
using Microsoft.Owin.Security;
|
||||||
using StructureMap.Graph;
|
|
||||||
|
|
||||||
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(InventoryTraker.Web.StructureMapConfig), "Configure")]
|
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(InventoryTraker.Web.StructureMapConfig), "Configure")]
|
||||||
namespace InventoryTraker.Web
|
namespace InventoryTraker.Web
|
||||||
@@ -42,6 +42,8 @@ namespace InventoryTraker.Web
|
|||||||
cfg.For<IAuthenticationManager>().Use(ctx => ctx.GetInstance<HttpRequestBase>().GetOwinContext().Authentication);
|
cfg.For<IAuthenticationManager>().Use(ctx => ctx.GetInstance<HttpRequestBase>().GetOwinContext().Authentication);
|
||||||
|
|
||||||
//TODO: Add other registries and configure your container (if needed)
|
//TODO: Add other registries and configure your container (if needed)
|
||||||
|
var mapper = AutoMapperConfig.Config.CreateMapper();
|
||||||
|
cfg.For<IMapper>().Use(x => mapper);
|
||||||
});
|
});
|
||||||
|
|
||||||
var resolver = new StructureMapDependencyResolver();
|
var resolver = new StructureMapDependencyResolver();
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using AutoMapper;
|
||||||
using InventoryTraker.Web.ActionResults;
|
using InventoryTraker.Web.ActionResults;
|
||||||
|
using InventoryTraker.Web.Data;
|
||||||
using InventoryTraker.Web.Utilities;
|
using InventoryTraker.Web.Utilities;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,12 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
public class InventoryController : ControllerBase
|
public class InventoryController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly AppDbContext _context;
|
private readonly AppDbContext _context;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
public InventoryController(AppDbContext context)
|
public InventoryController(AppDbContext context, IMapper mapper)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
|
_mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
@@ -30,7 +32,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
{
|
{
|
||||||
var viewModels =
|
var viewModels =
|
||||||
CurrentInventory()
|
CurrentInventory()
|
||||||
.ProjectTo<InventoryViewModel>()
|
.ProjectTo<InventoryViewModel>(_mapper.ConfigurationProvider)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
return BetterJson(viewModels);
|
return BetterJson(viewModels);
|
||||||
@@ -39,7 +41,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
public JsonResult Find(int id)
|
public JsonResult Find(int id)
|
||||||
{
|
{
|
||||||
var inventory = _context.Inventories.Find(id);
|
var inventory = _context.Inventories.Find(id);
|
||||||
var viewModel = Mapper.Map<InventoryViewModel>(inventory);
|
var viewModel = _mapper.Map<InventoryViewModel>(inventory);
|
||||||
return BetterJson(viewModel);
|
return BetterJson(viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +59,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
|
|
||||||
var viewModels =
|
var viewModels =
|
||||||
CurrentInventory()
|
CurrentInventory()
|
||||||
.ProjectTo<InventoryViewModel>()
|
.ProjectTo<InventoryViewModel>(_mapper.ConfigurationProvider)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
var excel = writer.Write(viewModels);
|
var excel = writer.Write(viewModels);
|
||||||
@@ -77,7 +79,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return GetModelStateErrorListJson();
|
return GetModelStateErrorListJson();
|
||||||
|
|
||||||
var inventory = Mapper.Map<Inventory>(form);
|
var inventory = _mapper.Map<Inventory>(form);
|
||||||
inventory.InventoryType = _context.InventoryTypes.Find(form.InventoryTypeId);
|
inventory.InventoryType = _context.InventoryTypes.Find(form.InventoryTypeId);
|
||||||
|
|
||||||
if (inventory.InventoryType == null)
|
if (inventory.InventoryType == null)
|
||||||
@@ -98,7 +100,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
};
|
};
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
|
|
||||||
var model = Mapper.Map<InventoryViewModel>(inventory);
|
var model = _mapper.Map<InventoryViewModel>(inventory);
|
||||||
return BetterJson(model);
|
return BetterJson(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +158,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
|
|
||||||
return BetterJson(CurrentInventory()
|
return BetterJson(CurrentInventory()
|
||||||
.ProjectTo<InventoryViewModel>()
|
.ProjectTo<InventoryViewModel>(_mapper.ConfigurationProvider)
|
||||||
.ToArray());
|
.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +209,8 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
|
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
|
|
||||||
return BetterJson(Mapper.Map<InventoryViewModel>(inventory));
|
return BetterJson(_mapper.Map<InventoryViewModel>(inventory));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
@@ -14,10 +13,12 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
public class InventoryTypeController : ControllerBase
|
public class InventoryTypeController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly AppDbContext _context;
|
private readonly AppDbContext _context;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
public InventoryTypeController(AppDbContext context)
|
public InventoryTypeController(AppDbContext context, IMapper mapper)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
|
_mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
@@ -29,7 +30,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
{
|
{
|
||||||
var viewModels = _context.InventoryTypes
|
var viewModels = _context.InventoryTypes
|
||||||
.OrderByDescending(x => x.Name)
|
.OrderByDescending(x => x.Name)
|
||||||
.ProjectTo<InventoryTypeViewModel>();
|
.ProjectTo<InventoryTypeViewModel>(_mapper.ConfigurationProvider);
|
||||||
|
|
||||||
return BetterJson(viewModels.ToArray());
|
return BetterJson(viewModels.ToArray());
|
||||||
}
|
}
|
||||||
@@ -41,7 +42,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
var viewModels =
|
var viewModels =
|
||||||
_context.InventoryTypes
|
_context.InventoryTypes
|
||||||
.OrderByDescending(x => x.Name)
|
.OrderByDescending(x => x.Name)
|
||||||
.ProjectTo<InventoryTypeViewModel>()
|
.ProjectTo<InventoryTypeViewModel>(_mapper.ConfigurationProvider)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
var excel = writer.Write(viewModels);
|
var excel = writer.Write(viewModels);
|
||||||
@@ -60,11 +61,11 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return GetModelStateErrorListJson();
|
return GetModelStateErrorListJson();
|
||||||
|
|
||||||
var inventoryType = Mapper.Map<InventoryType>(form);
|
var inventoryType = _mapper.Map<InventoryType>(form);
|
||||||
_context.InventoryTypes.Add(inventoryType);
|
_context.InventoryTypes.Add(inventoryType);
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
|
|
||||||
var model = Mapper.Map<InventoryTypeViewModel>(inventoryType);
|
var model = _mapper.Map<InventoryTypeViewModel>(inventoryType);
|
||||||
return BetterJson(model);
|
return BetterJson(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,11 +75,11 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
return GetModelStateErrorListJson();
|
return GetModelStateErrorListJson();
|
||||||
|
|
||||||
var inventoryType = _context.InventoryTypes.Find(form.Id);
|
var inventoryType = _context.InventoryTypes.Find(form.Id);
|
||||||
Mapper.Map(form, inventoryType);
|
_mapper.Map(form, inventoryType);
|
||||||
|
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
|
|
||||||
var model = Mapper.Map<InventoryTypeViewModel>(inventoryType);
|
var model = _mapper.Map<InventoryTypeViewModel>(inventoryType);
|
||||||
return BetterJson(model);
|
return BetterJson(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,16 +10,18 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
public class ProfileController : ControllerBase
|
public class ProfileController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ApplicationUserManager _userManager;
|
private readonly ApplicationUserManager _userManager;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
public ProfileController(ApplicationUserManager userManager)
|
public ProfileController(ApplicationUserManager userManager, IMapper mapper)
|
||||||
{
|
{
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
|
_mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
{
|
{
|
||||||
var user = _userManager.FindById(User.Identity.GetUserId());
|
var user = _userManager.FindById(User.Identity.GetUserId());
|
||||||
var model = Mapper.Map<ProfileForm>(user);
|
var model = _mapper.Map<ProfileForm>(user);
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,17 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
public class ReportController : ControllerBase
|
public class ReportController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ReportService _reportService;
|
private readonly ReportService _reportService;
|
||||||
|
private readonly DistributionReportWriter _distributionReportWriter;
|
||||||
|
private readonly MovementReportWriter _movementReportWriter;
|
||||||
|
|
||||||
public ReportController(ReportService reportService)
|
public ReportController(
|
||||||
|
ReportService reportService,
|
||||||
|
DistributionReportWriter distributionReportWriter,
|
||||||
|
MovementReportWriter movementReportWriter)
|
||||||
{
|
{
|
||||||
_reportService = reportService;
|
_reportService = reportService;
|
||||||
|
_distributionReportWriter = distributionReportWriter;
|
||||||
|
_movementReportWriter = movementReportWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@@ -32,8 +39,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
{
|
{
|
||||||
var report = _reportService.GetDistributionReport(startDate, endDate);
|
var report = _reportService.GetDistributionReport(startDate, endDate);
|
||||||
|
|
||||||
var writer = new DistributionReportWriter();
|
var excel = _distributionReportWriter.Write(report);
|
||||||
var excel = writer.Write(report);
|
|
||||||
|
|
||||||
var filename = $"InventoryDistributionReport{startDate:yyyyMMdd}-{endDate:yyyyMMdd}.xlsx";
|
var filename = $"InventoryDistributionReport{startDate:yyyyMMdd}-{endDate:yyyyMMdd}.xlsx";
|
||||||
|
|
||||||
@@ -61,8 +67,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
{
|
{
|
||||||
var report = _reportService.GetMovementReport(month);
|
var report = _reportService.GetMovementReport(month);
|
||||||
|
|
||||||
var writer = new MovementReportWriter();
|
var excel = _movementReportWriter.Write(report);
|
||||||
var excel = writer.Write(report);
|
|
||||||
|
|
||||||
var filename = $"MonthlyInventoryReport{report.Month:MMMMyyyy}.xlsx";
|
var filename = $"MonthlyInventoryReport{report.Month:MMMMyyyy}.xlsx";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Collections;
|
using System.Linq;
|
||||||
using System.Linq;
|
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using AutoMapper;
|
||||||
using AutoMapper.QueryableExtensions;
|
using AutoMapper.QueryableExtensions;
|
||||||
using InventoryTraker.Web.Attributes;
|
using InventoryTraker.Web.Attributes;
|
||||||
using InventoryTraker.Web.Core;
|
using InventoryTraker.Web.Core;
|
||||||
@@ -12,10 +12,12 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
public class TransactionController : ControllerBase
|
public class TransactionController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly AppDbContext _context;
|
private readonly AppDbContext _context;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
public TransactionController(AppDbContext context)
|
public TransactionController(AppDbContext context, IMapper mapper)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
|
_mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
@@ -27,7 +29,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
{
|
{
|
||||||
var viewModels =
|
var viewModels =
|
||||||
_context.Transactions
|
_context.Transactions
|
||||||
.ProjectTo<TransactionViewModel>()
|
.ProjectTo<TransactionViewModel>(_mapper.ConfigurationProvider)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
return BetterJson(viewModels);
|
return BetterJson(viewModels);
|
||||||
@@ -50,7 +52,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
|
|
||||||
var totalItems = _context.Transactions.Count();
|
var totalItems = _context.Transactions.Count();
|
||||||
var transactions = query
|
var transactions = query
|
||||||
.ProjectTo<TransactionViewModel>()
|
.ProjectTo<TransactionViewModel>(_mapper.ConfigurationProvider)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
return BetterJson(new { totalItems, transactions });
|
return BetterJson(new { totalItems, transactions });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
public class UserController : ControllerBase
|
public class UserController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ApplicationUserManager _userManager;
|
private readonly ApplicationUserManager _userManager;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
public UserController(ApplicationUserManager userManager)
|
public UserController(ApplicationUserManager userManager, IMapper mapper)
|
||||||
{
|
{
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
|
_mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
@@ -30,7 +32,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
var users =
|
var users =
|
||||||
_userManager
|
_userManager
|
||||||
.Users
|
.Users
|
||||||
.ProjectTo<UserViewModel>()
|
.ProjectTo<UserViewModel>(_mapper.ConfigurationProvider)
|
||||||
.OrderBy(u => u.UserName);
|
.OrderBy(u => u.UserName);
|
||||||
|
|
||||||
return BetterJson(users);
|
return BetterJson(users);
|
||||||
@@ -47,7 +49,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
new User
|
new User
|
||||||
{
|
{
|
||||||
Email = form.Email,
|
Email = form.Email,
|
||||||
UserName = form.UserName
|
UserName = form.UserName,
|
||||||
};
|
};
|
||||||
|
|
||||||
var identityResult = await _userManager.CreateAsync(user, form.Password);
|
var identityResult = await _userManager.CreateAsync(user, form.Password);
|
||||||
@@ -55,7 +57,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
if (!identityResult.Succeeded)
|
if (!identityResult.Succeeded)
|
||||||
return GetErrorListJson(identityResult.Errors.ToArray());
|
return GetErrorListJson(identityResult.Errors.ToArray());
|
||||||
|
|
||||||
return BetterJson(Mapper.Map<UserViewModel>(user));
|
return BetterJson(_mapper.Map<UserViewModel>(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
[ActionLog]
|
[ActionLog]
|
||||||
@@ -83,7 +85,7 @@ namespace InventoryTraker.Web.Controllers
|
|||||||
if (!identityResult.Succeeded)
|
if (!identityResult.Succeeded)
|
||||||
return GetErrorListJson(identityResult.Errors.ToArray());
|
return GetErrorListJson(identityResult.Errors.ToArray());
|
||||||
|
|
||||||
return BetterJson(Mapper.Map<UserViewModel>(user));
|
return BetterJson(_mapper.Map<UserViewModel>(user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,8 +43,8 @@
|
|||||||
<HintPath>..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>
|
<HintPath>..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="AutoMapper, Version=4.2.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
|
<Reference Include="AutoMapper, Version=5.1.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\AutoMapper.4.2.0\lib\net45\AutoMapper.dll</HintPath>
|
<HintPath>..\packages\AutoMapper.5.1.1\lib\net45\AutoMapper.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="ClosedXML, Version=0.76.0.0, Culture=neutral, PublicKeyToken=fd1eb21b62ae805b, processorArchitecture=MSIL">
|
<Reference Include="ClosedXML, Version=0.76.0.0, Culture=neutral, PublicKeyToken=fd1eb21b62ae805b, processorArchitecture=MSIL">
|
||||||
@@ -71,10 +71,6 @@
|
|||||||
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Heroic.AutoMapper, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\packages\Heroic.AutoMapper.2.0.0\lib\net45\Heroic.AutoMapper.dll</HintPath>
|
|
||||||
<Private>True</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Heroic.Web.IoC, Version=4.1.2.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="Heroic.Web.IoC, Version=4.1.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Heroic.Web.IoC.4.1.2\lib\net45\Heroic.Web.IoC.dll</HintPath>
|
<HintPath>..\packages\Heroic.Web.IoC.4.1.2\lib\net45\Heroic.Web.IoC.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Heroic.AutoMapper;
|
using AutoMapper;
|
||||||
using InventoryTraker.Web.Core;
|
using InventoryTraker.Web.Core;
|
||||||
|
|
||||||
namespace InventoryTraker.Web.Models
|
namespace InventoryTraker.Web.Models
|
||||||
{
|
{
|
||||||
public class InventoryAddForm : IMapTo<Inventory>
|
public class InventoryAddForm
|
||||||
{
|
{
|
||||||
[HiddenInput(DisplayValue = false)]
|
[HiddenInput(DisplayValue = false)]
|
||||||
[Required]
|
[Required]
|
||||||
@@ -22,5 +22,13 @@ namespace InventoryTraker.Web.Models
|
|||||||
public DateTime AddedDate { get; set; }
|
public DateTime AddedDate { get; set; }
|
||||||
|
|
||||||
public string Memo { get; set; }
|
public string Memo { get; set; }
|
||||||
|
|
||||||
|
public class AutoMapperProfile : Profile
|
||||||
|
{
|
||||||
|
public AutoMapperProfile()
|
||||||
|
{
|
||||||
|
CreateMap<InventoryAddForm, Inventory>();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Heroic.AutoMapper;
|
using AutoMapper;
|
||||||
using InventoryTraker.Web.Core;
|
using InventoryTraker.Web.Core;
|
||||||
|
|
||||||
namespace InventoryTraker.Web.Models
|
namespace InventoryTraker.Web.Models
|
||||||
{
|
{
|
||||||
public class InventoryTypeViewModel : IMapFrom<InventoryType>, IMapTo<InventoryType>
|
public class InventoryTypeViewModel
|
||||||
{
|
{
|
||||||
[HiddenInput]
|
[HiddenInput]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@@ -33,5 +33,14 @@ namespace InventoryTraker.Web.Models
|
|||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public decimal PricePerCase { get; set; }
|
public decimal PricePerCase { get; set; }
|
||||||
|
|
||||||
|
public class AutoMapperProfile : Profile
|
||||||
|
{
|
||||||
|
public AutoMapperProfile()
|
||||||
|
{
|
||||||
|
CreateMap<InventoryType, InventoryTypeViewModel>();
|
||||||
|
CreateMap<InventoryTypeViewModel, InventoryType>();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Heroic.AutoMapper;
|
|
||||||
using InventoryTraker.Web.Core;
|
using InventoryTraker.Web.Core;
|
||||||
|
|
||||||
namespace InventoryTraker.Web.Models
|
namespace InventoryTraker.Web.Models
|
||||||
{
|
{
|
||||||
public class InventoryViewModel : IMapFrom<Inventory>, IHaveCustomMappings
|
public class InventoryViewModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
@@ -31,9 +30,11 @@ namespace InventoryTraker.Web.Models
|
|||||||
|
|
||||||
public bool IsExpired => ExpirationDate < DateTime.Today;
|
public bool IsExpired => ExpirationDate < DateTime.Today;
|
||||||
|
|
||||||
public void CreateMappings(IMapperConfiguration configuration)
|
public class AutoMapperProfile : Profile
|
||||||
{
|
{
|
||||||
configuration.CreateMap<Inventory, InventoryViewModel>()
|
public AutoMapperProfile()
|
||||||
|
{
|
||||||
|
CreateMap<Inventory, InventoryViewModel>()
|
||||||
.ForMember(d => d.InventoryTypeId, opt => opt.MapFrom(s => s.InventoryType.Id))
|
.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.Name, opt => opt.MapFrom(s => s.InventoryType.Name))
|
||||||
.ForMember(d => d.UnitsPerCase, opt => opt.MapFrom(s => s.InventoryType.UnitsPerCase))
|
.ForMember(d => d.UnitsPerCase, opt => opt.MapFrom(s => s.InventoryType.UnitsPerCase))
|
||||||
@@ -43,4 +44,5 @@ namespace InventoryTraker.Web.Models
|
|||||||
.ForMember(d => d.AddedDate, opt => opt.MapFrom(s => s.AddedDate));
|
.ForMember(d => d.AddedDate, opt => opt.MapFrom(s => s.AddedDate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Heroic.AutoMapper;
|
|
||||||
using InventoryTraker.Web.Core;
|
using InventoryTraker.Web.Core;
|
||||||
|
|
||||||
namespace InventoryTraker.Web.Models
|
namespace InventoryTraker.Web.Models
|
||||||
{
|
{
|
||||||
public class ProfileForm : IMapFrom<User>, IHaveCustomMappings
|
public class ProfileForm
|
||||||
{
|
{
|
||||||
[Required, Display(Name = "Full Name", Prompt = "Full Name (ex: John Doe)...")]
|
[Required, Display(Name = "Full Name", Prompt = "Full Name (ex: John Doe)...")]
|
||||||
public string FullName { get; set; }
|
public string FullName { get; set; }
|
||||||
@@ -13,11 +12,14 @@ namespace InventoryTraker.Web.Models
|
|||||||
[Required, DataType(DataType.EmailAddress), Display(Prompt = "your@email.com...")]
|
[Required, DataType(DataType.EmailAddress), Display(Prompt = "your@email.com...")]
|
||||||
public string EmailAddress { get; set; }
|
public string EmailAddress { get; set; }
|
||||||
|
|
||||||
public void CreateMappings(IMapperConfiguration configuration)
|
public class AutoMapperProfile : Profile
|
||||||
{
|
{
|
||||||
configuration.CreateMap<User, ProfileForm>()
|
public AutoMapperProfile()
|
||||||
|
{
|
||||||
|
CreateMap<User, ProfileForm>()
|
||||||
.ForMember(d => d.FullName, opt => opt.MapFrom(s => s.UserName))
|
.ForMember(d => d.FullName, opt => opt.MapFrom(s => s.UserName))
|
||||||
.ForMember(d => d.EmailAddress, opt => opt.MapFrom(s => s.Email));
|
.ForMember(d => d.EmailAddress, opt => opt.MapFrom(s => s.Email));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Heroic.AutoMapper;
|
|
||||||
using InventoryTraker.Web.Core;
|
using InventoryTraker.Web.Core;
|
||||||
|
|
||||||
namespace InventoryTraker.Web.Models
|
namespace InventoryTraker.Web.Models
|
||||||
{
|
{
|
||||||
public class TransactionViewModel : IMapFrom<Transaction>, IHaveCustomMappings
|
public class TransactionViewModel
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@@ -37,9 +36,11 @@ namespace InventoryTraker.Web.Models
|
|||||||
|
|
||||||
public DateTime Timestamp { get; set; }
|
public DateTime Timestamp { get; set; }
|
||||||
|
|
||||||
public void CreateMappings(IMapperConfiguration configuration)
|
public class AutoMapperProfile : Profile
|
||||||
{
|
{
|
||||||
configuration.CreateMap<Transaction, TransactionViewModel>()
|
public AutoMapperProfile()
|
||||||
|
{
|
||||||
|
CreateMap<Transaction, TransactionViewModel>()
|
||||||
.ForMember(d => d.InventoryId,
|
.ForMember(d => d.InventoryId,
|
||||||
opt => opt.MapFrom(s => s.Inventory.Id))
|
opt => opt.MapFrom(s => s.Inventory.Id))
|
||||||
.ForMember(d => d.Name,
|
.ForMember(d => d.Name,
|
||||||
@@ -60,4 +61,5 @@ namespace InventoryTraker.Web.Models
|
|||||||
opt => opt.MapFrom(s => s.CurrentQuantity - s.AddedQuantity + s.RemovedQuantity));
|
opt => opt.MapFrom(s => s.CurrentQuantity - s.AddedQuantity + s.RemovedQuantity));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Heroic.AutoMapper;
|
using AutoMapper;
|
||||||
using InventoryTraker.Web.Core;
|
using InventoryTraker.Web.Core;
|
||||||
|
|
||||||
namespace InventoryTraker.Web.Models
|
namespace InventoryTraker.Web.Models
|
||||||
{
|
{
|
||||||
public class UserViewModel : IMapFrom<User>
|
public class UserViewModel
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
[StringLength(128)]
|
[StringLength(128)]
|
||||||
@@ -20,5 +20,13 @@ namespace InventoryTraker.Web.Models
|
|||||||
{
|
{
|
||||||
return $"UserName: {UserName}, email: {Email}";
|
return $"UserName: {UserName}, email: {Email}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class AutoMapperProfile : Profile
|
||||||
|
{
|
||||||
|
public AutoMapperProfile()
|
||||||
|
{
|
||||||
|
CreateMap<User, UserViewModel>();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,10 +12,12 @@ namespace InventoryTraker.Web.Services
|
|||||||
public class ReportService
|
public class ReportService
|
||||||
{
|
{
|
||||||
private readonly AppDbContext _context;
|
private readonly AppDbContext _context;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
public ReportService(AppDbContext context)
|
public ReportService(AppDbContext context, IMapper mapper)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
|
_mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DistributionReport[] GetDistributionReport(DateTime startDate, DateTime endDate)
|
public DistributionReport[] GetDistributionReport(DateTime startDate, DateTime endDate)
|
||||||
@@ -42,7 +44,7 @@ namespace InventoryTraker.Web.Services
|
|||||||
Date = item.Date,
|
Date = item.Date,
|
||||||
Destination = item.Destination,
|
Destination = item.Destination,
|
||||||
Transactions =
|
Transactions =
|
||||||
Mapper.Map<IList<Transaction>, IList<TransactionViewModel>>
|
_mapper.Map<IList<Transaction>, IList<TransactionViewModel>>
|
||||||
(item.Transactions).ToArray()
|
(item.Transactions).ToArray()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -149,7 +151,7 @@ namespace InventoryTraker.Web.Services
|
|||||||
into grp
|
into grp
|
||||||
select new MovementReportItem
|
select new MovementReportItem
|
||||||
{
|
{
|
||||||
InventoryType = Mapper.Map<InventoryTypeViewModel>(grp.Key),
|
InventoryType = _mapper.Map<InventoryTypeViewModel>(grp.Key),
|
||||||
BeginningQuantity = grp.Sum(g => g.BeginningQuantity),
|
BeginningQuantity = grp.Sum(g => g.BeginningQuantity),
|
||||||
AddedQuantity = grp.Sum(g => g.AddedQuantity),
|
AddedQuantity = grp.Sum(g => g.AddedQuantity),
|
||||||
TotalAvailableQuantity = grp.Sum(g => g.TotalAvailableQuantity),
|
TotalAvailableQuantity = grp.Sum(g => g.TotalAvailableQuantity),
|
||||||
|
|||||||
@@ -6,14 +6,13 @@ using ClosedXML.Excel;
|
|||||||
using CsvHelper;
|
using CsvHelper;
|
||||||
using CsvHelper.Configuration;
|
using CsvHelper.Configuration;
|
||||||
using CsvHelper.Excel;
|
using CsvHelper.Excel;
|
||||||
using Heroic.AutoMapper;
|
|
||||||
using InventoryTraker.Web.Models;
|
using InventoryTraker.Web.Models;
|
||||||
|
|
||||||
namespace InventoryTraker.Web.Utilities
|
namespace InventoryTraker.Web.Utilities
|
||||||
{
|
{
|
||||||
public class DistributionReportWriter
|
public class DistributionReportWriter
|
||||||
{
|
{
|
||||||
public class DistributionReportExportItem : IMapFrom<TransactionViewModel>, IHaveCustomMappings
|
public class DistributionReportExportItem
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string UnitsPerCaseContainerType { get; set; }
|
public string UnitsPerCaseContainerType { get; set; }
|
||||||
@@ -22,18 +21,21 @@ namespace InventoryTraker.Web.Utilities
|
|||||||
public string UnitQuantity { get; set; }
|
public string UnitQuantity { get; set; }
|
||||||
public string Weight { 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.Name, opt => opt.MapFrom(i => i.Name))
|
||||||
.ForMember(d => d.UnitsPerCaseContainerType,
|
.ForMember(d => d.UnitsPerCaseContainerType,
|
||||||
opt => opt.MapFrom(i => $"{i.UnitsPerCase} / {i.ContainerType}"))
|
opt => opt.MapFrom(i => $"{i.UnitsPerCase} / {i.ContainerType}"))
|
||||||
.ForMember(d => d.ExpirationDate,
|
.ForMember(d => d.ExpirationDate,
|
||||||
opt => opt.MapFrom(i => i.ExpirationDate.ToShortDateString()))
|
opt => opt.MapFrom(i => i.ExpirationDate.ToShortDateString()))
|
||||||
.ForMember(d => d.UnitQuantity,
|
.ForMember(d => d.UnitQuantity,
|
||||||
opt => opt.MapFrom(i => i.RemovedQuantity*i.UnitsPerCase))
|
opt => opt.MapFrom(i => i.RemovedQuantity * i.UnitsPerCase))
|
||||||
.ForMember(d => d.Weight,
|
.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)
|
public byte[] Write(IEnumerable<DistributionReport> reports)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
@@ -75,7 +84,7 @@ namespace InventoryTraker.Web.Utilities
|
|||||||
writer.WriteField(report.Date.ToShortDateString());
|
writer.WriteField(report.Date.ToShortDateString());
|
||||||
writer.NextRecord();
|
writer.NextRecord();
|
||||||
var items =
|
var items =
|
||||||
Mapper.Map<IEnumerable<TransactionViewModel>, IEnumerable<DistributionReportExportItem>>
|
_mapper.Map<IEnumerable<TransactionViewModel>, IEnumerable<DistributionReportExportItem>>
|
||||||
(report.Transactions)
|
(report.Transactions)
|
||||||
.OrderBy(i => i.Name);
|
.OrderBy(i => i.Name);
|
||||||
writer.WriteRecords(items);
|
writer.WriteRecords(items);
|
||||||
|
|||||||
@@ -7,14 +7,13 @@ using ClosedXML.Excel;
|
|||||||
using CsvHelper;
|
using CsvHelper;
|
||||||
using CsvHelper.Configuration;
|
using CsvHelper.Configuration;
|
||||||
using CsvHelper.Excel;
|
using CsvHelper.Excel;
|
||||||
using Heroic.AutoMapper;
|
|
||||||
using InventoryTraker.Web.Models;
|
using InventoryTraker.Web.Models;
|
||||||
|
|
||||||
namespace InventoryTraker.Web.Utilities
|
namespace InventoryTraker.Web.Utilities
|
||||||
{
|
{
|
||||||
public class MovementReportWriter
|
public class MovementReportWriter
|
||||||
{
|
{
|
||||||
public class MovementReportExportItem : IMapFrom<MovementReportItem>, IHaveCustomMappings
|
public class MovementReportExportItem
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string UnitsPerCaseContainerType { get; set; }
|
public string UnitsPerCaseContainerType { get; set; }
|
||||||
@@ -25,7 +24,9 @@ namespace InventoryTraker.Web.Utilities
|
|||||||
public string AdjustmentQuantity { get; set; }
|
public string AdjustmentQuantity { get; set; }
|
||||||
public string EndingQuantity { get; set; }
|
public string EndingQuantity { get; set; }
|
||||||
|
|
||||||
public void CreateMappings(IMapperConfiguration configuration)
|
public class AutoMapperProfile : Profile
|
||||||
|
{
|
||||||
|
public AutoMapperProfile()
|
||||||
{
|
{
|
||||||
Func<int, int, string> formatCases =
|
Func<int, int, string> formatCases =
|
||||||
(cases, unitsPerCase) => $"{cases * unitsPerCase} ({cases} cs)";
|
(cases, unitsPerCase) => $"{cases * unitsPerCase} ({cases} cs)";
|
||||||
@@ -42,7 +43,7 @@ namespace InventoryTraker.Web.Utilities
|
|||||||
? "- " + hideEmptyCases(cases, unitsPerCase)
|
? "- " + hideEmptyCases(cases, unitsPerCase)
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
configuration.CreateMap<MovementReportItem, MovementReportExportItem>()
|
CreateMap<MovementReportItem, MovementReportExportItem>()
|
||||||
.ForMember(d => d.Name, opt => opt.MapFrom(i => i.InventoryType.Name))
|
.ForMember(d => d.Name, opt => opt.MapFrom(i => i.InventoryType.Name))
|
||||||
.ForMember(d => d.UnitsPerCaseContainerType,
|
.ForMember(d => d.UnitsPerCaseContainerType,
|
||||||
opt => opt.MapFrom(i => i.InventoryType.UnitsPerCaseContainerType))
|
opt => opt.MapFrom(i => i.InventoryType.UnitsPerCaseContainerType))
|
||||||
@@ -66,6 +67,7 @@ namespace InventoryTraker.Web.Utilities
|
|||||||
formatCases(i.EndingQuantity, i.InventoryType.UnitsPerCase)));
|
formatCases(i.EndingQuantity, i.InventoryType.UnitsPerCase)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private sealed class MovementReportMap : CsvClassMap<MovementReportExportItem>
|
private sealed class MovementReportMap : CsvClassMap<MovementReportExportItem>
|
||||||
{
|
{
|
||||||
@@ -82,6 +84,13 @@ namespace InventoryTraker.Web.Utilities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
|
public MovementReportWriter(IMapper mapper)
|
||||||
|
{
|
||||||
|
_mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] Write(MovementReport report)
|
public byte[] Write(MovementReport report)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
@@ -104,7 +113,7 @@ namespace InventoryTraker.Web.Utilities
|
|||||||
writer.WriteField<string>($"Month: {report.Month:MMMM yyyy}");
|
writer.WriteField<string>($"Month: {report.Month:MMMM yyyy}");
|
||||||
writer.NextRecord();
|
writer.NextRecord();
|
||||||
var items =
|
var items =
|
||||||
Mapper.Map<IEnumerable<MovementReportItem>, IEnumerable<MovementReportExportItem>>
|
_mapper.Map<IEnumerable<MovementReportItem>, IEnumerable<MovementReportExportItem>>
|
||||||
(report.Items)
|
(report.Items)
|
||||||
.OrderBy(i => i.Name);
|
.OrderBy(i => i.Name);
|
||||||
writer.WriteRecords(items);
|
writer.WriteRecords(items);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
ViewBag.Title = "Your Profile";
|
ViewBag.Title = "Your Profile";
|
||||||
}
|
}
|
||||||
|
|
||||||
<h1 class="page-header">Update Your Profile</h1>
|
<h1 class="page-header">Update @ViewBag.Title</h1>
|
||||||
<form novalidate
|
<form novalidate
|
||||||
name="vm.form"
|
name="vm.form"
|
||||||
ng-controller="EditProfileController as vm"
|
ng-controller="EditProfileController as vm"
|
||||||
@@ -36,15 +36,3 @@
|
|||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
@section Scripts
|
|
||||||
{
|
|
||||||
<script>
|
|
||||||
var url = '@(Html.BuildUrlFromExpression<ProfileController>(c => c.Update(null)))';
|
|
||||||
|
|
||||||
window.app.constant('editProfileConfig', {
|
|
||||||
saveUrl: url
|
|
||||||
});
|
|
||||||
|
|
||||||
window.app.constant('model', @Html.JsonFor(Model));
|
|
||||||
</script>
|
|
||||||
}
|
|
||||||
@@ -82,6 +82,10 @@
|
|||||||
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
|
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
|
||||||
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
|
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-5.1.1.0" newVersion="5.1.1.0" />
|
||||||
|
</dependentAssembly>
|
||||||
</assemblyBinding>
|
</assemblyBinding>
|
||||||
</runtime>
|
</runtime>
|
||||||
<entityFramework>
|
<entityFramework>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
window.app.controller('EditProfileController',
|
window.app.controller('EditProfileController',
|
||||||
function($http, editProfileConfig, model) {
|
function($http, model) {
|
||||||
var vm = this;
|
var vm = this;
|
||||||
|
|
||||||
vm.profile = model;
|
vm.profile = model;
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
vm.errorMessage = null;
|
vm.errorMessage = null;
|
||||||
vm.success = false;
|
vm.success = false;
|
||||||
|
|
||||||
$http.post(editProfileConfig.saveUrl, vm.profile)
|
$http.post("/Profile/Update", vm.profile)
|
||||||
.success(function() {
|
.success(function() {
|
||||||
vm.success = true;
|
vm.success = true;
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<package id="angular-strap" version="2.3.1" targetFramework="net451" />
|
<package id="angular-strap" version="2.3.1" targetFramework="net451" />
|
||||||
<package id="angular-ui-grid" version="3.1.1" targetFramework="net451" />
|
<package id="angular-ui-grid" version="3.1.1" targetFramework="net451" />
|
||||||
<package id="Antlr" version="3.5.0.2" targetFramework="net451" />
|
<package id="Antlr" version="3.5.0.2" targetFramework="net451" />
|
||||||
<package id="AutoMapper" version="4.2.0" targetFramework="net451" />
|
<package id="AutoMapper" version="5.1.1" targetFramework="net451" />
|
||||||
<package id="bootstrap" version="3.3.7" targetFramework="net451" />
|
<package id="bootstrap" version="3.3.7" targetFramework="net451" />
|
||||||
<package id="ClosedXML" version="0.76.0" targetFramework="net451" />
|
<package id="ClosedXML" version="0.76.0" targetFramework="net451" />
|
||||||
<package id="CsvHelper" version="2.16.3.0" targetFramework="net451" />
|
<package id="CsvHelper" version="2.16.3.0" targetFramework="net451" />
|
||||||
@@ -15,7 +15,6 @@
|
|||||||
<package id="EntityFramework" version="6.1.3" targetFramework="net451" />
|
<package id="EntityFramework" version="6.1.3" targetFramework="net451" />
|
||||||
<package id="filesaver" version="1.1.20151003" targetFramework="net451" />
|
<package id="filesaver" version="1.1.20151003" targetFramework="net451" />
|
||||||
<package id="FontAwesome" version="4.6.3" targetFramework="net451" />
|
<package id="FontAwesome" version="4.6.3" targetFramework="net451" />
|
||||||
<package id="Heroic.AutoMapper" version="2.0.0" targetFramework="net451" />
|
|
||||||
<package id="Heroic.Web.IoC" version="4.1.2" targetFramework="net451" />
|
<package id="Heroic.Web.IoC" version="4.1.2" targetFramework="net451" />
|
||||||
<package id="HtmlTags" version="3.0.0.186" targetFramework="net451" />
|
<package id="HtmlTags" version="3.0.0.186" targetFramework="net451" />
|
||||||
<package id="Humanizer" version="1.33.7" targetFramework="net451" />
|
<package id="Humanizer" version="1.33.7" targetFramework="net451" />
|
||||||
|
|||||||
Reference in New Issue
Block a user