public static TypeOfOperationViewModel MapToViewModel(TypeOfOperation typeOfOperation) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <TypeOfOperation, TypeOfOperationViewModel>(); }); return(config.CreateMapper().Map <TypeOfOperationViewModel>(typeOfOperation)); }
public static FlightLogViewModel MapToViewModel(FlightLog flightLog) { var config = new MapperConfiguration(cfg => {; cfg.CreateMap <FlightLog, FlightLogViewModel>(); //.ForMember(x=>x.FlightLogTypeOfOperations, opt=>opt.Ignore()); }); var flightLogViewModel = config.CreateMapper().Map <FlightLogViewModel>(flightLog); flightLogViewModel.TypeOfOperationViewModels = new List <TypeOfOperationViewModel>(); foreach (var typeOfOperation in flightLog.FlightLogTypeOfOperations.Select(x => x.TypeOfOperation).ToList()) { flightLogViewModel.TypeOfOperationViewModels.Add(TypeOfOperation.MapToViewModel(typeOfOperation)); } // TODO: manually automap flightlogtypeofoperations return(flightLogViewModel); }