public MappingProfiles() { //CreateMap<PagedRequestViewModel, IPagedQuery>() // member mappings explicit because of an externally defined class // .ForMember(dest => dest.Page, opt => opt.MapFrom(src => src.Page)) // .ForMember(dest => dest.ResultsPerPage, opt => opt.MapFrom(src => src.ResultsPerPage)); CreateMap <GetCardTemplateViewModel, CardTemplateQuery>() .ForMember(dest => dest.Rank, opt => opt.MapFrom(src => RanksEnumeration.FromName(src.Rank, true))) .ForMember(dest => dest.Suit, opt => opt.MapFrom(src => SuitsEnumeration.FromName(src.Suit, true))); CreateMap <GetWidgetsViewModelV2, CardTemplateQuery>(); //CreateMap<SieveModel, WidgetsQuery>() // might need to extend the models with an interface to avoid excessive mapping expressions //.ForMember(dest => dest.SortFilterPaging, opt => opt.MapFrom(src => src)); CreateMap <CreateWidgetViewModel, CreateWidgetCommand>() .ForMember(dest => dest.Classification, opt => opt.MapFrom(src => SuitsEnumeration.FromValue(ushort.Parse(src.Classification)))); CreateMap <DeprecateWidgetViewModel, DeprecateWidgetCommand>(); }
public override Deck ReadJson(JsonReader reader, Type objectType, Deck existingValue, bool hasExistingValue, JsonSerializer serializer) { JObject jObject = JObject.Load(reader); string debug = jObject.ToString(); Guid id = Guid.Parse(jObject["@metadata"]["@id"].Value <string>()); // Manual LINQ token conversion, but could also reuse DTO's from below IList <PlayingCard> ravenCards = jObject["Cards"] .Children() .Select(x => new PlayingCard(x["Id"].Value <string>(), CardTemplate.NewTemplate(RanksEnumeration.FromValue(x["Rank"].Value <ushort>()), SuitsEnumeration.FromValue(x["Suit"].Value <ushort>())))).ToList(); var serializedDeck = Deck.FromCards(ravenCards); return(serializedDeck); }