Ejemplo n.º 1
0
        public IEnumerable <TEntity> GetEntitiesByParent(string parentType, string parentId)
        {
            var snapshots = _snapshotStore.GetChildSnapshots <TSnapshot>(parentType, parentId);

            foreach (var snapshot in snapshots)
            {
                yield return(LoadEntityFromSnapshot(snapshot));
            }
        }
Ejemplo n.º 2
0
        private TransactionDictionary GroupTransactions()
        {
            var groupedTransactions   = new Dictionary <CategoryMonthKey, decimal>();
            var transacations         = _snapshotStore.GetAllSnapshots <TransactionSnapshot>().Where(t => !t.IsDeleted).ToList();
            var transactionReferences = transacations.Select(t => new EntityReference(nameof(Transaction), t.EntityID)).ToList();
            var subTransactionsLookup = _snapshotStore.GetChildSnapshots <SubTransactionSnapshot>(transactionReferences)?.ToDictionary(kvp => kvp.Key.EntityID, kvp => kvp.Value);

            foreach (var transaction in transacations)
            {
                if (transaction.TransactionType == TransactionTypes.Normal)
                {
                    CategoryMonthKey category = GetCategoryMonthKey(transaction);
                    if (category == null)
                    {
                        continue;
                    }

                    if (groupedTransactions.ContainsKey(category))
                    {
                        groupedTransactions[category] += GetTransactionAmount(transaction);
                    }
                    else
                    {
                        groupedTransactions[category] = GetTransactionAmount(transaction);
                    }
                }
                else if (transaction.TransactionType == TransactionTypes.SplitTransaction)
                {
                    if (subTransactionsLookup != null &&
                        subTransactionsLookup.TryGetValue(transaction.EntityID, out List <SubTransactionSnapshot> subTransactions))
                    {
                        foreach (var subTransaction in subTransactions)
                        {
                            CategoryMonthKey category = GetCategoryMonthKey(transaction, subTransaction);
                            if (category == null)
                            {
                                continue;
                            }

                            if (groupedTransactions.ContainsKey(category))
                            {
                                groupedTransactions[category] += GetTransactionAmount(subTransaction);
                            }
                            else
                            {
                                groupedTransactions[category] = GetTransactionAmount(subTransaction);
                            }
                        }
                    }
                }
            }

            return(groupedTransactions);
        }
Ejemplo n.º 3
0
        public IEnumerable <TEntity> GetEntitiesByParent(string parentType, string parentId)
        {
            var snapshots          = _snapshotStore.GetChildSnapshots <TSnapshot>(parentType, parentId).ToList();
            var subEntitySnapshots = GetSubEntitySnapshotLookup(snapshots);

            foreach (var snapshot in snapshots)
            {
                if (subEntitySnapshots == null)
                {
                    yield return(LoadEntityFromSnapshot(snapshot, null));
                }
                else
                {
                    EntityReference       snapshotReference = new EntityReference(typeof(TEntity).Name, snapshot.EntityID);
                    List <EntitySnapshot> subEntities       = null;
                    if (!subEntitySnapshots.TryGetValue(snapshotReference, out subEntities))
                    {
                        subEntities = new List <EntitySnapshot>();
                    }

                    yield return(LoadEntityFromSnapshot(snapshot, subEntities));
                }
            }
        }