/// <summary> /// Maps the collection (List<VoteToRecord>) of cast votes to /// a collection of <see cref="Vote"/> entities. (IEnumerable<Vote>) /// </summary> /// <param name="recordVotesInput">The record votes input.</param> /// <returns></returns> public virtual IEnumerable <Vote> MapCastVotesToVotes( RecordVotesInputModel recordVotesInput) { var voterId = recordVotesInput.VoterId; ////public class VoteToRecord //// public int CandidateID { get; set; } //// public string VoteDate { get; set; } // first, convert a VoteToRecord to a Vote entity, or, in this // case, the collection. var mapperConfig = new MapperConfiguration(cfg => { cfg.CreateMap <VoteToRecord, Vote>() .BeforeMap((src, dest) => { dest.VoterId = voterId; dest.CandidateId = src.CandidateID; dest.Candidate = _candidatesRepository.GetById(src.CandidateID); dest.Voter = _votersRepository.GetById(voterId); }) .ForMember( dest => dest.Id, opt => opt.MapFrom(src => src.CandidateID)); }); var iMapper = mapperConfig.CreateMapper(); var votesToRecord = iMapper.Map <List <VoteToRecord>, IEnumerable <Vote> >(recordVotesInput.VotesToRecord); return(votesToRecord); }