You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
4.5 KiB
C#

10 months ago
using AutoMapper;
using BookingWeb.DB.Model;
using BookingWeb.Models;
using Resources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace BookingWeb
{
public static class AutoMapperConfig
{
public static void Init()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<UserRegistViewModel, SysUser>();
cfg.CreateMap<SysUser, CurrentUser>();
cfg.CreateMap<SysUser, CurrentCompany>();
cfg.CreateMap<SysUser, SubAccountEditViewModel>();
cfg.CreateMap<SubAccountEditViewModel, SysUser>();
cfg.CreateMap<SysUser, SubAccountListViewModel>()
.ForMember(x => x.STATUS, map => map.MapFrom(t => t.STATUS == UserStatus.Active.ToString() ? LangSubAccount.EnumStatusActive : LangSubAccount.EnumStatusDisable))
;
cfg.CreateMap<OrderEditViewModel, OP_SEAE_ORDER>()
.ForMember(x => x.ISCONTAINERSOC, map => map.MapFrom(t => t.ISCONTAINERSOC ? "1" : "0"))
.ForMember(x => x.MODIFYTIME, map => map.MapFrom(t => new DateTime(t.MODIFYTIME)));
cfg.CreateMap<ConfirmEditViewModel, OP_SEAE_SI>()
.ForMember(x => x.ISCONTAINERSOC, map => map.MapFrom(t => t.ISCONTAINERSOC ? "1" : "0"))
.ForMember(x => x.MODIFYTIME, map => map.MapFrom(t => new DateTime(t.MODIFYTIME)))
;
cfg.CreateMap<OP_SEAE_ORDER, OrderEditViewModel>()
.ForMember(x => x.ISCONTAINERSOC, map => map.MapFrom(t => t.ISCONTAINERSOC == "1" ? true : false))
.ForMember(x => x.ETD, map => map.MapFrom(t => t.ETD.HasValue ? t.ETD.Value.ToString("yyyy-MM-dd") : ""))
.ForMember(x => x.MODIFYTIME, map => map.MapFrom(t => t.MODIFYTIME.HasValue ? t.MODIFYTIME.Value.Ticks : 0))
;
cfg.CreateMap<OP_SEAE_ORDER, ConfirmEditViewModel>()
.ForMember(x => x.ISCONTAINERSOC, map => map.MapFrom(t => t.ISCONTAINERSOC == "1" ? true : false))
.ForMember(x => x.ETD, map => map.MapFrom(t => t.ETD.HasValue ? t.ETD.Value.ToString("yyyy-MM-dd") : ""))
;
cfg.CreateMap<OP_SEAE_SI, ConfirmEditViewModel>()
.ForMember(x => x.ISCONTAINERSOC, map => map.MapFrom(t => t.ISCONTAINERSOC == "1" ? true : false))
.ForMember(x => x.ETD, map => map.MapFrom(t => t.ETD.HasValue ? t.ETD.Value.ToString("yyyy-MM-dd") : ""))
.ForMember(x => x.MODIFYTIME, map => map.MapFrom(t => t.MODIFYTIME.HasValue ? t.MODIFYTIME.Value.Ticks : 0))
;
cfg.CreateMap<OP_CTN, OpCtnOrderEditViewModel>();
cfg.CreateMap<OP_CTN, OpCtnListDetailViewModel>();
cfg.CreateMap<OpCtnOrderEditViewModel, OP_CTN>();
cfg.CreateMap<OP_CTN, OpCtnConfirmEditViewModel>();
cfg.CreateMap<OpCtnConfirmEditViewModel, OP_CTN>();
cfg.CreateMap<OP_TEMPLATE, TemplateListViewModel>();
cfg.CreateMap<OP_TEMPLATE, TemplateSaveViewModel>();
cfg.CreateMap<TemplateSaveViewModel, OP_TEMPLATE>();
cfg.CreateMap<OP_SEAE_ORDER, OrderListViewModel>()
.ForMember(x => x.BSSTATUS_NAME, map => map.MapFrom(t => ((OrderStatus)Enum.Parse(typeof(OrderStatus), t.BSSTATUS)).GetDesp()))
.ForMember(x => x.SISTATUS_NAME, map => map.MapFrom(t => ((OrderConfirmStatus)Enum.Parse(typeof(OrderConfirmStatus), t.SISTATUS)).GetDesp()))
.ForMember(x => x.ETD, map => map.MapFrom(t => t.ETD.HasValue ? t.ETD.Value.ToString("yyyy-MM-dd") : ""))
;
cfg.CreateMap<OP_SEAE_SI, ConfirmListViewModel>()
.ForMember(x => x.BSSTATUS_NAME, map => map.MapFrom(t => ((OrderConfirmStatus)Enum.Parse(typeof(OrderConfirmStatus), t.BSSTATUS)).GetDesp()))
.ForMember(x => x.ETD, map => map.MapFrom(t => t.ETD.HasValue ? t.ETD.Value.ToString("yyyy-MM-dd") : ""))
;
cfg.CreateMap<OP_LOG, OpLogListViewModel>()
.ForMember(x => x.OpTime, map => map.MapFrom(t => t.OpTime.ToString("yyyy-MM-dd HH:mm:ss")))
.ForMember(x => x.Module, map => map.MapFrom(t => ((OpLogModule)Enum.Parse(typeof(OpLogModule), t.Module)).GetDesp()))
.ForMember(x => x.Type, map => map.MapFrom(t => ((OpLogType)Enum.Parse(typeof(OpLogType), t.Type)).GetDesp()))
;
});
}
}
}