/NewsManagement_VS2010/src/NewsManagement/NMA.Infrastructure.AutoMapper/DefaultProfile.cs
# · C# · 131 lines · 109 code · 16 blank · 6 comment · 0 complexity · 5f02f6777d02ce74551f784dd5e5660a MD5 · raw file
- using System;
- using AutoMapper;
-
- namespace NMA.Infrastructure.AutoMapper
- {
- using NMA.Infrastructure.NHibernate.DomainObject;
- using NMA.Infrastructure.NHibernate.Service.Event;
- using NMA.Domain.Model.DTO;
-
- public class DefaultProfile : Profile
- {
- protected override string ProfileName
- {
- get { return "DefaultProfile"; }
- }
-
- protected override void Configure()
- {
- #region Event mapping
-
- //Mapper.CreateMap<Audit, CategoryAuditEvent>()
- // .ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.UserName))
- // .ForMember(dest => dest.UserAction, opt => opt.MapFrom(src => src.UserAction))
- // .ForMember(dest => dest.DateEvent, opt => opt.MapFrom(src => src.DateEvent));
-
- Mapper.CreateMap<AuditEvent, Audit>()
- .ForMember(dest => dest.Id, opt => opt.UseValue<Guid>(Guid.NewGuid()))
- .ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.UserName))
- .ForMember(dest => dest.UserAction, opt => opt.MapFrom(src => src.UserAction))
- .ForMember(dest => dest.DateEvent, opt => opt.MapFrom(src => src.DateEvent));
-
- #endregion
-
- #region DTO mapping
-
- // mapping from DTO to entity
- Mapper.CreateMap<Category, CategoryDTO>()
- .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
- .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
- .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
- .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
- .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
- .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
-
- Mapper.CreateMap<News, NewsDTO>()
- .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
- .ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Title))
- .ForMember(dest => dest.ShortDescription, opt => opt.MapFrom(src => src.ShortDescription))
- .ForMember(dest => dest.Content, opt => opt.MapFrom(src => src.Content))
- .ForMember(dest => dest.IsPublish, opt => opt.MapFrom(src => src.IsPublish))
- .ForMember(dest => dest.PublishedDate, opt => opt.MapFrom(src => src.PublishedDate))
- .ForMember(dest => dest.PublishedPerson, opt => opt.MapFrom(src => src.PublishedPerson))
- .ForMember(dest => dest.NumberOfView, opt => opt.MapFrom(src => src.NumberOfView))
- .ForMember(dest => dest.Image, opt => opt.MapFrom(src => src.Image))
- .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
- .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
- .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
- .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
-
- Mapper.CreateMap<Poll, PollDTO>()
- .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
- .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
- .ForMember(dest => dest.Value, opt => opt.MapFrom(src => src.Value))
- .ForMember(dest => dest.VoteDate, opt => opt.MapFrom(src => src.VoteDate))
- .ForMember(dest => dest.WhoVote, opt => opt.MapFrom(src => src.WhoVote))
- .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
- .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
- .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
- .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
-
- Mapper.CreateMap<Resources, ResourcesDTO>()
- .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
- .ForMember(dest => dest.ResourceType, opt => opt.MapFrom(src => src.ResourceType))
- .ForMember(dest => dest.CultureCode, opt => opt.MapFrom(src => src.CultureCode))
- .ForMember(dest => dest.ResourceKey, opt => opt.MapFrom(src => src.ResourceKey))
- .ForMember(dest => dest.ResourceValue, opt => opt.MapFrom(src => src.ResourceValue))
- .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
- .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
- .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
- .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
-
- // Mapping from entity to DTO
- Mapper.CreateMap<CategoryDTO, Category>()
- .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
- .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
- .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
- .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
- .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
- .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
-
- Mapper.CreateMap<NewsDTO, News>()
- .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
- .ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Title))
- .ForMember(dest => dest.ShortDescription, opt => opt.MapFrom(src => src.ShortDescription))
- .ForMember(dest => dest.Content, opt => opt.MapFrom(src => src.Content))
- .ForMember(dest => dest.IsPublish, opt => opt.MapFrom(src => src.IsPublish))
- .ForMember(dest => dest.PublishedDate, opt => opt.MapFrom(src => src.PublishedDate))
- .ForMember(dest => dest.PublishedPerson, opt => opt.MapFrom(src => src.PublishedPerson))
- .ForMember(dest => dest.NumberOfView, opt => opt.MapFrom(src => src.NumberOfView))
- .ForMember(dest => dest.Image, opt => opt.MapFrom(src => src.Image))
- .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
- .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
- .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
- .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
-
- Mapper.CreateMap<PollDTO, Poll>()
- .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
- .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
- .ForMember(dest => dest.Value, opt => opt.MapFrom(src => src.Value))
- .ForMember(dest => dest.VoteDate, opt => opt.MapFrom(src => src.VoteDate))
- .ForMember(dest => dest.WhoVote, opt => opt.MapFrom(src => src.WhoVote))
- .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
- .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
- .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
- .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
-
- Mapper.CreateMap<ResourcesDTO, Resources>()
- .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
- .ForMember(dest => dest.ResourceType, opt => opt.MapFrom(src => src.ResourceType))
- .ForMember(dest => dest.CultureCode, opt => opt.MapFrom(src => src.CultureCode))
- .ForMember(dest => dest.ResourceKey, opt => opt.MapFrom(src => src.ResourceKey))
- .ForMember(dest => dest.ResourceValue, opt => opt.MapFrom(src => src.ResourceValue))
- .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate))
- .ForMember(dest => dest.UpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
- .ForMember(dest => dest.CreatedUser, opt => opt.MapFrom(src => src.CreatedUser))
- .ForMember(dest => dest.UpdatedUser, opt => opt.MapFrom(src => src.UpdatedUser));
-
- #endregion
- }
- }
- }