Esempio n. 1
0
        public async Task <IEnumerable <EpcisEvent> > ToList(CancellationToken cancellationToken)
        {
            _parameters.SetLimit(_limit > 0 ? _limit : int.MaxValue);
            var events = await _unitOfWork.Query <EpcisEventEntity, ErrorDeclarationEntity>(_sqlTemplate.RawSql, _parameters.Values, (evt, ed) => evt.ErrorDeclaration = ed, "declaration_time", cancellationToken);

            using (var reader = await _unitOfWork.FetchMany(PgSqlEventRequests.RelatedQuery, new { EventIds = events.Select(x => x.Id).ToArray() }, cancellationToken))
            {
                var epcs = await reader.ReadAsync <EpcEntity>();

                var fields = await reader.ReadAsync <CustomFieldEntity>();

                var transactions = await reader.ReadAsync <BusinessTransactionEntity>();

                var sourceDests = await reader.ReadAsync <SourceDestinationEntity>();

                var correctiveEventIds = await reader.ReadAsync <CorrectiveEventIdEntity>();

                foreach (var evt in events)
                {
                    evt.Epcs                  = epcs.Where(x => x.EventId == evt.Id).ToList <Epc>();
                    evt.CustomFields          = CreateHierarchy(fields.Where(x => x.EventId == evt.Id));
                    evt.BusinessTransactions  = transactions.Where(x => x.EventId == evt.Id).ToList <BusinessTransaction>();
                    evt.SourceDestinationList = sourceDests.Where(x => x.EventId == evt.Id).ToList <SourceDestination>();

                    if (evt.ErrorDeclaration != null)
                    {
                        evt.ErrorDeclaration.CorrectiveEventIds = correctiveEventIds.Where(x => x.EventId == evt.Id).ToList <CorrectiveEventId>();
                    }
                }
            }

            return(events);
        }
Esempio n. 2
0
        public async Task <IEnumerable <EpcisMasterData> > ToList(string[] attributes, bool includeChildren, CancellationToken cancellationToken)
        {
            _parameters.SetLimit(_limit > 0 ? _limit : int.MaxValue);
            var masterData = await _unitOfWork.Query <EpcisMasterData>(_sqlTemplate.RawSql, _parameters.Values, cancellationToken);

            if (attributes != null)
            {
                var query            = !attributes.Any() ? PgSqlMasterdataRequests.AllAttributeQuery : PgSqlMasterdataRequests.AttributeQuery;
                var relatedAttribute = await _unitOfWork.Query <MasterDataAttribute>(query, new { Ids = masterData.Select(x => x.Id).ToArray(), Attributes = attributes }, cancellationToken);

                masterData.ForEach(m => m.Attributes.AddRange(relatedAttribute.Where(a => a.ParentId == m.Id && a.ParentType == m.Type)));
            }
            if (includeChildren)
            {
                var children = await _unitOfWork.Query <EpcisMasterDataHierarchy>("SELECT type, parent_id, children_id FROM cbv.hierarchy WHERE parent_id = ANY(@Ids);", new { Ids = masterData.Select(x => x.Id).ToArray() }, cancellationToken);

                masterData.ForEach(m => m.Children.AddRange(children.Where(c => c.ParentId == m.Id && c.Type == m.Type)));
            }

            return(masterData);
        }
 public async Task <Subscription> GetById(string subscriptionId, CancellationToken cancellationToken)
 {
     return((await _unitOfWork.Query <Subscription>($"{PgSqlSubscriptionRequests.List} WHERE s.subscription_id = @Id", new { Id = subscriptionId }, cancellationToken)).SingleOrDefault());
 }