コード例 #1
0
        public async Task GetTruckRevenueGroupBySettlementAsync()
        {
            List <SettlementHistory> settlements = await repository.GetSettlementsAsync();

            IEnumerable <SettlementHistory> orderedSettlements = settlements
                                                                 .OrderByDescending(s => s.WeekNumber)
                                                                 .OrderByDescending(s => s.Year);

            List <TruckReport> reports = new List <TruckReport>();

            System.Console.WriteLine(TruckReport.Header);

            foreach (var s in orderedSettlements)
            {
                var trucks = s.Credits.GroupBy(c => c.TruckId);
                foreach (var truck in trucks)
                {
                    TruckReport report = new TruckReport()
                    {
                        SettlementDate = s.SettlementDate
                    };
                    report.Year            = s.Year;
                    report.WeekNumber      = s.WeekNumber;
                    report.TruckId         = truck.Key;
                    report.Miles           = truck.Sum(t => t.Miles);
                    report.TotalPaid       = truck.Sum(t => t.TotalPaid);
                    report.TotalDeductions = s.Deductions.Where(d => d.TruckId == truck.Key).Sum(d => d.TotalDeductions);
                    reports.Add(report);
                    System.Console.WriteLine(report);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Forces an update on all settlements.  This is normally used to update the serialized
        /// object after a schema change.
        /// </summary>
        public string[] UpdateAll()
        {
            System.Console.WriteLine($"Updating all settlements.");
            List <SettlementHistory> savedSettlements = null;

            var task = Task.Run(async() =>
            {
                SettlementRepository repository = new SettlementRepository();
                savedSettlements = await repository.GetSettlementsAsync();
                repository.SaveSettlements(savedSettlements);
            });

            task.Wait();

            string[] settlementIds = savedSettlements?.Select(s => s.SettlementId).ToArray();
            return(settlementIds);
        }
コード例 #3
0
        /// <summary>
        /// Downloads and returns 'max' settlements from panther that we have not persisted, ordered by
        /// descending date.
        /// <summary>
        private async Task <List <KeyValuePair <string, SettlementHistory> > > DownloadMissingSettlements(PantherClient panther, int max = 10)
        {
            List <SettlementHistory> settlements = await panther.GetSettlementsAsync();

            SettlementRepository     repository       = new SettlementRepository();
            List <SettlementHistory> savedSettlements = await repository.GetSettlementsAsync();

            // Don't try to convert settlements we've already persisted.
            List <SettlementHistory> settlementsToDownload = settlements.Except(savedSettlements, new SettlementHistoryComparer())
                                                             .OrderByDescending(s => s.SettlementDate)
                                                             .Take(max)
                                                             .ToList();

            List <KeyValuePair <string, SettlementHistory> > settlementsToConvert =
                await panther.DownloadSettlementsAsync(settlementsToDownload);

            return(settlementsToConvert);
        }
コード例 #4
0
        public string[] UpdateHeadersFromPanther(PantherClient panther)
        {
            System.Console.WriteLine($"Updating settlements for company: {panther.Company}.");
            List <SettlementHistory> settlementsToUpdate = null;

            var task = Task.Run(async() =>
            {
                List <SettlementHistory> settlements = await panther.GetSettlementsAsync();

                SettlementRepository repository           = new SettlementRepository();
                List <SettlementHistory> savedSettlements = await repository.GetSettlementsAsync();

                settlementsToUpdate =
                    settlements.Intersect(savedSettlements, new SettlementHistoryComparer())
                    .ToList();
                repository.SaveSettlements(settlementsToUpdate);
            });

            task.Wait();

            string[] settlementIds = settlementsToUpdate?.Select(s => s.SettlementId).ToArray();
            return(settlementIds);
        }