public static void AutoMapInit() { #region 系统管理 #region 菜单管理 Mapper.CreateMap <Menu, MenuDto>(); Mapper.CreateMap <MenuDto, Menu>() .AfterMap((src, dest) => dest.Id = LsIdGenerator.CreateIdentity()); #endregion #region 角色管理 Mapper.CreateMap <Role, RoleDto>(); Mapper.CreateMap <RoleDto, Role>() .AfterMap((src, dest) => dest.Id = LsIdGenerator.CreateIdentity()); #endregion #region 用户管理 Mapper.CreateMap <User, UserDto>() .ForMember(ts => ts.CreatedTime, opt => opt.MapFrom(td => td.CreatedTime.ToString("yyyy-MM-dd HH:mm:ss"))) .ForMember(ts => ts.LastUpdatedTime, opt => opt.MapFrom(td => td.LastUpdatedTime.ToString("yyyy-MM-dd HH:mm:ss"))) .ForMember(ts => ts.Role, opt => opt.MapFrom(td => td.Role)); Mapper.CreateMap <UserDto, User>() .ForMember(ts => ts.UserName, opt => opt.MapFrom(td => td.UserName)) .ForMember(ts => ts.LoginId, opt => opt.MapFrom(td => td.UserName)) .AfterMap((src, dest) => dest.Id = LsIdGenerator.CreateIdentity()); #endregion #endregion }
public static void AutoMapInit() { Mapper.Initialize(config => { #region 系统管理 #region 菜单管理 config.CreateMap <Menu, MenuDto>() .ForMember(ts => ts.MenuType, opt => opt.MapFrom(t => (int)t.MenuType)) .ForMember(ts => ts.MenuType, opt => opt.MapFrom(t => t.MenuType.ToString())); config.CreateMap <MenuDto, Menu>() .ForMember(ts => ts.MenuType, opt => opt.MapFrom(t => Enum.Parse(typeof(MenuType), t.MenuType))) .AfterMap((src, dest) => dest.Id = LsIdGenerator.CreateIdentity()); #endregion #region 操作管理 config.CreateMap <AuthAction, ActionDto>(); config.CreateMap <ActionDto, AuthAction>() .AfterMap((src, dest) => dest.Id = LsIdGenerator.CreateIdentity()); #endregion #region 角色管理 config.CreateMap <Role, RoleDto>(); config.CreateMap <RoleDto, Role>() .AfterMap((src, dest) => dest.Id = LsIdGenerator.CreateIdentity()); #endregion #region 用户管理 config.CreateMap <User, UserDto>() .ForMember(ts => ts.CreatedTime, opt => opt.MapFrom(td => td.CreatedTime.ToString(DateTimeFormatterConstString.DateTimeH24))) .ForMember(ts => ts.LastUpdatedTime, opt => opt.MapFrom(td => td.LastUpdatedTime.ToString(DateTimeFormatterConstString.DateTimeH24))) .ForMember(ts => ts.Role, opt => opt.MapFrom(td => td.Role)); config.CreateMap <UserDto, User>() .ForMember(ts => ts.LoginId, opt => opt.MapFrom(td => td.Name)) .AfterMap((src, dest) => dest.Id = LsIdGenerator.CreateIdentity()); #endregion #region 权限管理 config.CreateMap <PermissionDto, Permission>() .AfterMap((src, dest) => dest.Id = LsIdGenerator.CreateIdentity()); config.CreateMap <Permission, PermissionDto>() .ForMember(ts => ts.MenuName, opt => opt.MapFrom(td => td.Menu.Name)) .ForMember(ts => ts.MenuType, opt => opt.MapFrom(td => td.Menu.MenuType.ToString())) .ForMember(ts => ts.Url, opt => opt.MapFrom(td => td.Menu.Url ?? "")) .ForMember(ts => ts.ActionName, opt => opt.MapFrom(td => td.Action.Name)) .ForMember(ts => ts.Template, opt => opt.MapFrom(td => td.Action.Template)); config.CreateMap <Permission, PermissionMenuDto>() .ForMember(ts => ts.MenuName, opt => opt.MapFrom(td => td.Menu.Name)) .ForMember(ts => ts.Url, opt => opt.MapFrom(td => td.Menu.Url)) .ForMember(ts => ts.Icon, opt => opt.MapFrom(td => td.Menu.Icon)); config.CreateMap <Permission, PermissionMenuActionDto>() .ForMember(ts => ts.MenuType, opt => opt.MapFrom(td => td.Menu.MenuType.ToString())) .ForMember(ts => ts.Icon, opt => opt.MapFrom(td => td.Menu.Icon)); #endregion #endregion }); }
protected override void Seed(Example.Repository.ExampleDbContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // var tenantId = 1; context.Users.AddOrUpdate(p => p.Name, new User { Id = LsIdGenerator.CreateIdentity(), Role = new Role { Id = LsIdGenerator.CreateIdentity(), Name = "管理员", Description = "管理员", TenantId = tenantId }, LoginId = "admin", Name = "admin", Password = "******", Phone = "18795950000", Email = "*****@*****.**", RealName = "管理员", TenantId = tenantId, CreatedTime = DateTime.Now, LastUpdatedTime = DateTime.Now, }); }