public EventCustomerResultBloodLabParser Save(EventCustomerResultBloodLabParser domain)
        {
            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var linqMetaData = new LinqMetaData(adapter);
                var entity       = (from ecrblp in linqMetaData.EventCustomerResultBloodLabParser where ecrblp.EventCustomerResultId == domain.EventCustomerResultId select ecrblp).SingleOrDefault();
                if (entity == null || !entity.IsActive)
                {
                    entity = Mapper.Map <EventCustomerResultBloodLabParser, EventCustomerResultBloodLabParserEntity>(domain);
                    adapter.SaveEntity(entity, true, false);
                    return(Mapper.Map <EventCustomerResultBloodLabParserEntity, EventCustomerResultBloodLabParser>(entity));
                }

                return(domain);
            }
        }
        private void Save(IEnumerable <EventCustomerScreeningAggregate> eventCustomerScreeningAggregates, long uploadedBy)
        {
            if (eventCustomerScreeningAggregates == null)
            {
                return;
            }

            var eventids = eventCustomerScreeningAggregates.Select(x => x.EventId).ToArray();

            var events = _eventRepository.GetEvents(eventids);

            foreach (var eventCustomerScreeningAggregate in eventCustomerScreeningAggregates)
            {
                var eventCustomerResult = SaveEventCustomerResult(eventCustomerScreeningAggregate.EventId, eventCustomerScreeningAggregate.CustomerId, uploadedBy);

                SaveEventCustomerResultBloodLab(eventCustomerResult.Id, true);

                foreach (var testResult in eventCustomerScreeningAggregate.TestResults)
                {
                    var eventData = events.First(x => x.Id == eventCustomerResult.EventId);

                    var isNewResultFlow = eventData.EventDate >= _settings.ResultFlowChangeDate;

                    testResult.IsNewResultFlow = isNewResultFlow;

                    SaveTestResult(testResult, eventCustomerScreeningAggregate.EventId, eventCustomerScreeningAggregate.CustomerId, uploadedBy, eventCustomerResult.ResultState, eventCustomerResult.IsPartial, isNewResultFlow);
                    try
                    {
                        if (testResult.TestType == TestType.Psa)
                        {
                            var eventCustomerResultBloodLabParse = new EventCustomerResultBloodLabParser()
                            {
                                BloodLabId            = (long)BloodLabsType.Hanson,
                                EventCustomerResultId = eventCustomerResult.Id,
                                IsActive = true
                            };
                            _eventCustomerResultBloodLabParserRepository.Save(eventCustomerResultBloodLabParse);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error("Event Customer Result Blood Lab Parser : " + ex.Message + "\n" + ex.StackTrace, ex);
                    }
                }
            }
        }