public T StartMapper <T>(IntegrationCapeStock integration) where T : class, IEntityBase { var config = new MapperConfiguration(cfg => { cfg.CreateMap <IntegrationCapeStock, T>() .ForMember(x => x.CompanyControl, opt => opt.Ignore()) .ForMember(x => x.CompanyControlId, opt => opt.Ignore()) .ForMember(x => x.DateRegistration, opt => opt.Ignore()) .ForMember(x => x.DateUpdate, opt => opt.Ignore()) .ForMember(x => x.Id, opt => opt.Ignore()) .ForMember(x => x.Integration, opt => opt.UseValue(true)) .ForMember(x => x.Integration, opt => opt.Ignore()) .ForMember(x => x.Status, opt => opt.Ignore()) .ForMember(x => x.UserControl, opt => opt.Ignore()) .ForMember(x => x.UserControlId, opt => opt.Ignore()); }); IMapper mapper = config.CreateMapper(); var obj = mapper.Map <IntegrationCapeStock, T>(integration); var propertyIntegrationCapeStockId = typeof(T).GetProperty("IntegrationCapeStockId"); if (propertyIntegrationCapeStockId != null) { propertyIntegrationCapeStockId.SetValue(obj, integration.Id); } return(obj); }
public bool InsertOrUpdate(IntegrationCapeStock integrationCapeStock) { var integration = _epr.Search(integrationCapeStock.GetExpressionByRelation()).FirstOrDefault(); if (integration != null) { integration = _stockMapper.StartMapper(integrationCapeStock, integration); } if (integration != null) { _epr.InsertOrUpdate(integration); if (_conn.Save()) { InputStock inputStock = null; OutputStock outputStock = null; switch (integration.TypeIntegration) { case TypeIntegration.InputStock: inputStock = _inputStockApp.Search(c => c.IntegrationCapeStockId == integration.Id).FirstOrDefault(); _inputStockApp.InsertOrUpdate(_stockMapper.StartMapper(integration, inputStock ?? new InputStock())); break; case TypeIntegration.OutputStock: outputStock = _outputStockApp.Search(c => c.IntegrationCapeStockId == integration.Id).FirstOrDefault(); _outputStockApp.InsertOrUpdate(_stockMapper.StartMapper(integration, outputStock ?? new OutputStock())); break; default: return(false); } } else { return(false); } } else { _epr.InsertOrUpdate(integrationCapeStock); if (_conn.Save()) { switch (integrationCapeStock.TypeIntegration) { case TypeIntegration.InputStock: _inputStockApp.InsertOrUpdate(_stockMapper.StartMapper <InputStock>(integrationCapeStock)); break; case TypeIntegration.OutputStock: _outputStockApp.InsertOrUpdate(_stockMapper.StartMapper <OutputStock>(integrationCapeStock)); break; default: return(false); } } else { return(false); } } return(_conn.Save()); }