public void AddOrUpdate(GetMortgageInput input) { var config = new ConfigurationStore(new TypeMapFactory(), AutoMapper.Mappers.MapperRegistry.Mappers); var mapper = new MappingEngine(config); config.CreateMap<MortgageDto, Mortgage>().ConstructUsing(model => { if (model.Id == 0) { Mortgage toAdd = new Mortgage(); _mortgageRepository.Insert(toAdd); return toAdd; } else { return _mortgageRepository.Get(model.Id); } }).ForMember(x => x.LandProperty, o => o.Ignore()); try { mapper.Map<MortgageDto, Mortgage>(input.MortgageToUpdate); } catch (Exception e) { throw e; } }
public async Task<GetMortgageOutput> Get(GetMortgageInput input) { GetMortgageOutput output = new GetMortgageOutput(); if (input.MortgageId > 0) { output.SingleMortgage = Mapper.Map<MortgageDto>(await _mortgageRepository.GetAsync(input.MortgageId)); } else { output.SingleMortgage = Mapper.Map<MortgageDto>(new Mortgage()); } return output; }