Update automapper
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using Heroic.AutoMapper;
|
||||
using AutoMapper;
|
||||
using InventoryTraker.Web.Core;
|
||||
|
||||
namespace InventoryTraker.Web.Models
|
||||
{
|
||||
public class InventoryAddForm : IMapTo<Inventory>
|
||||
public class InventoryAddForm
|
||||
{
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
[Required]
|
||||
@@ -22,5 +22,13 @@ namespace InventoryTraker.Web.Models
|
||||
public DateTime AddedDate { 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.Web.Mvc;
|
||||
using Heroic.AutoMapper;
|
||||
using AutoMapper;
|
||||
using InventoryTraker.Web.Core;
|
||||
|
||||
namespace InventoryTraker.Web.Models
|
||||
{
|
||||
public class InventoryTypeViewModel : IMapFrom<InventoryType>, IMapTo<InventoryType>
|
||||
public class InventoryTypeViewModel
|
||||
{
|
||||
[HiddenInput]
|
||||
public int Id { get; set; }
|
||||
@@ -33,5 +33,14 @@ namespace InventoryTraker.Web.Models
|
||||
|
||||
[Required]
|
||||
public decimal PricePerCase { get; set; }
|
||||
|
||||
public class AutoMapperProfile : Profile
|
||||
{
|
||||
public AutoMapperProfile()
|
||||
{
|
||||
CreateMap<InventoryType, InventoryTypeViewModel>();
|
||||
CreateMap<InventoryTypeViewModel, InventoryType>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using AutoMapper;
|
||||
using Heroic.AutoMapper;
|
||||
using InventoryTraker.Web.Core;
|
||||
|
||||
namespace InventoryTraker.Web.Models
|
||||
{
|
||||
public class InventoryViewModel : IMapFrom<Inventory>, IHaveCustomMappings
|
||||
public class InventoryViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
@@ -31,16 +30,19 @@ namespace InventoryTraker.Web.Models
|
||||
|
||||
public bool IsExpired => ExpirationDate < DateTime.Today;
|
||||
|
||||
public void CreateMappings(IMapperConfiguration configuration)
|
||||
public class AutoMapperProfile : Profile
|
||||
{
|
||||
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));
|
||||
public AutoMapperProfile()
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using AutoMapper;
|
||||
using Heroic.AutoMapper;
|
||||
using InventoryTraker.Web.Core;
|
||||
|
||||
namespace InventoryTraker.Web.Models
|
||||
{
|
||||
public class ProfileForm : IMapFrom<User>, IHaveCustomMappings
|
||||
public class ProfileForm
|
||||
{
|
||||
[Required, Display(Name = "Full Name", Prompt = "Full Name (ex: John Doe)...")]
|
||||
public string FullName { get; set; }
|
||||
@@ -13,11 +12,14 @@ namespace InventoryTraker.Web.Models
|
||||
[Required, DataType(DataType.EmailAddress), Display(Prompt = "your@email.com...")]
|
||||
public string EmailAddress { get; set; }
|
||||
|
||||
public void CreateMappings(IMapperConfiguration configuration)
|
||||
public class AutoMapperProfile : Profile
|
||||
{
|
||||
configuration.CreateMap<User, ProfileForm>()
|
||||
.ForMember(d => d.FullName, opt => opt.MapFrom(s => s.UserName))
|
||||
.ForMember(d => d.EmailAddress, opt => opt.MapFrom(s => s.Email));
|
||||
public AutoMapperProfile()
|
||||
{
|
||||
CreateMap<User, ProfileForm>()
|
||||
.ForMember(d => d.FullName, opt => opt.MapFrom(s => s.UserName))
|
||||
.ForMember(d => d.EmailAddress, opt => opt.MapFrom(s => s.Email));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Heroic.AutoMapper;
|
||||
using AutoMapper;
|
||||
using InventoryTraker.Web.Core;
|
||||
|
||||
namespace InventoryTraker.Web.Models
|
||||
{
|
||||
public class UserViewModel : IMapFrom<User>
|
||||
public class UserViewModel
|
||||
{
|
||||
[Required]
|
||||
[StringLength(128)]
|
||||
@@ -20,5 +20,13 @@ namespace InventoryTraker.Web.Models
|
||||
{
|
||||
return $"UserName: {UserName}, email: {Email}";
|
||||
}
|
||||
|
||||
public class AutoMapperProfile : Profile
|
||||
{
|
||||
public AutoMapperProfile()
|
||||
{
|
||||
CreateMap<User, UserViewModel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user