/NewsManagement_VS2010/src/NewsManagement/NMA.Infrastructure.AutoMapper/DefaultProfile.cs

# · C# · 131 lines · 109 code · 16 blank · 6 comment · 0 complexity · 5f02f6777d02ce74551f784dd5e5660a MD5 · raw file

  1. using System;
  2. using AutoMapper;
  3. namespace NMA.Infrastructure.AutoMapper
  4. {
  5. using NMA.Infrastructure.NHibernate.DomainObject;
  6. using NMA.Infrastructure.NHibernate.Service.Event;
  7. using NMA.Domain.Model.DTO;
  8. public class DefaultProfile : Profile
  9. {
  10. protected override string ProfileName
  11. {
  12. get { return "DefaultProfile"; }
  13. }
  14. protected override void Configure()
  15. {
  16. #region Event mapping
  17. //Mapper.CreateMap<Audit, CategoryAuditEvent>()
  18. // .ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.UserName))
  19. // .ForMember(dest => dest.UserAction, opt => opt.MapFrom(src => src.UserAction))
  20. // .ForMember(dest => dest.DateEvent, opt => opt.MapFrom(src => src.DateEvent));
  21. Mapper.CreateMap<AuditEvent, Audit>()
  22. .ForMember(dest => dest.Id, opt => opt.UseValue<Guid>(Guid.NewGuid()))
  23. .ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.UserName))
  24. .ForMember(dest => dest.UserAction, opt => opt.MapFrom(src => src.UserAction))
  25. .ForMember(dest => dest.DateEvent, opt => opt.MapFrom(src => src.DateEvent));
  26. #endregion
  27. #region DTO mapping
  28. // mapping from DTO to entity
  29. Mapper.CreateMap<Category, CategoryDTO>()
  30. .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
  31. .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
  32. .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
  33. .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
  34. .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
  35. .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
  36. Mapper.CreateMap<News, NewsDTO>()
  37. .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
  38. .ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Title))
  39. .ForMember(dest => dest.ShortDescription, opt => opt.MapFrom(src => src.ShortDescription))
  40. .ForMember(dest => dest.Content, opt => opt.MapFrom(src => src.Content))
  41. .ForMember(dest => dest.IsPublish, opt => opt.MapFrom(src => src.IsPublish))
  42. .ForMember(dest => dest.PublishedDate, opt => opt.MapFrom(src => src.PublishedDate))
  43. .ForMember(dest => dest.PublishedPerson, opt => opt.MapFrom(src => src.PublishedPerson))
  44. .ForMember(dest => dest.NumberOfView, opt => opt.MapFrom(src => src.NumberOfView))
  45. .ForMember(dest => dest.Image, opt => opt.MapFrom(src => src.Image))
  46. .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
  47. .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
  48. .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
  49. .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
  50. Mapper.CreateMap<Poll, PollDTO>()
  51. .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
  52. .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
  53. .ForMember(dest => dest.Value, opt => opt.MapFrom(src => src.Value))
  54. .ForMember(dest => dest.VoteDate, opt => opt.MapFrom(src => src.VoteDate))
  55. .ForMember(dest => dest.WhoVote, opt => opt.MapFrom(src => src.WhoVote))
  56. .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
  57. .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
  58. .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
  59. .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
  60. Mapper.CreateMap<Resources, ResourcesDTO>()
  61. .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
  62. .ForMember(dest => dest.ResourceType, opt => opt.MapFrom(src => src.ResourceType))
  63. .ForMember(dest => dest.CultureCode, opt => opt.MapFrom(src => src.CultureCode))
  64. .ForMember(dest => dest.ResourceKey, opt => opt.MapFrom(src => src.ResourceKey))
  65. .ForMember(dest => dest.ResourceValue, opt => opt.MapFrom(src => src.ResourceValue))
  66. .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
  67. .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
  68. .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
  69. .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
  70. // Mapping from entity to DTO
  71. Mapper.CreateMap<CategoryDTO, Category>()
  72. .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
  73. .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
  74. .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
  75. .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
  76. .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
  77. .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
  78. Mapper.CreateMap<NewsDTO, News>()
  79. .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
  80. .ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Title))
  81. .ForMember(dest => dest.ShortDescription, opt => opt.MapFrom(src => src.ShortDescription))
  82. .ForMember(dest => dest.Content, opt => opt.MapFrom(src => src.Content))
  83. .ForMember(dest => dest.IsPublish, opt => opt.MapFrom(src => src.IsPublish))
  84. .ForMember(dest => dest.PublishedDate, opt => opt.MapFrom(src => src.PublishedDate))
  85. .ForMember(dest => dest.PublishedPerson, opt => opt.MapFrom(src => src.PublishedPerson))
  86. .ForMember(dest => dest.NumberOfView, opt => opt.MapFrom(src => src.NumberOfView))
  87. .ForMember(dest => dest.Image, opt => opt.MapFrom(src => src.Image))
  88. .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
  89. .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
  90. .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
  91. .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
  92. Mapper.CreateMap<PollDTO, Poll>()
  93. .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
  94. .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
  95. .ForMember(dest => dest.Value, opt => opt.MapFrom(src => src.Value))
  96. .ForMember(dest => dest.VoteDate, opt => opt.MapFrom(src => src.VoteDate))
  97. .ForMember(dest => dest.WhoVote, opt => opt.MapFrom(src => src.WhoVote))
  98. .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
  99. .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
  100. .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
  101. .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
  102. Mapper.CreateMap<ResourcesDTO, Resources>()
  103. .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
  104. .ForMember(dest => dest.ResourceType, opt => opt.MapFrom(src => src.ResourceType))
  105. .ForMember(dest => dest.CultureCode, opt => opt.MapFrom(src => src.CultureCode))
  106. .ForMember(dest => dest.ResourceKey, opt => opt.MapFrom(src => src.ResourceKey))
  107. .ForMember(dest => dest.ResourceValue, opt => opt.MapFrom(src => src.ResourceValue))
  108. .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
  109. .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
  110. .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
  111. .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
  112. #endregion
  113. }
  114. }
  115. }