BudgetAnalyser.Engine.Services.TransactionManagerService.PopulateGroupByBucketCollection C# (CSharp) Method

PopulateGroupByBucketCollection() public method

Populates a collection grouped by bucket with date sorted transactions contained in each group.
public PopulateGroupByBucketCollection ( bool groupByBucket ) : IEnumerable
groupByBucket bool True if the UI is currently showing the transactions grouped by bucket, false if not.
return IEnumerable
        public IEnumerable<TransactionGroupedByBucket> PopulateGroupByBucketCollection(bool groupByBucket)
        {
            this.sortedByBucket = groupByBucket;
            if (StatementModel == null)
            {
                // This can occur if the statement file is closed while viewing in GroupByBucket Mode.
                return new TransactionGroupedByBucket[] { };
            }

            if (this.sortedByBucket)
            {
                // SortByBucket == true so group and sort by bucket.
                IEnumerable<TransactionGroupedByBucket> query = StatementModel.Transactions
                    .GroupBy(t => t.BudgetBucket)
                    .OrderBy(g => g.Key)
                    .Select(group => new TransactionGroupedByBucket(group, group.Key));
                return new List<TransactionGroupedByBucket>(query);
            }
            // When viewing transactions by date, databinding pulls data directly from the StatementModel.
            // As for the GroupByBucket Collection this can be cleared.
            return new TransactionGroupedByBucket[] { };
        }