Exemple #1
0
        private List <DealershipPerformanceStatus> BuildStatuses(IEnumerable <int> dealershipIds, DateTime start, DateTime end)
        {
            var statuses = new List <DealershipPerformanceStatus>();

            foreach (var id in dealershipIds)
            {
                // select N+1 - potentially bad for performance and efficiency
                // re-using existing domain code - quick to implement
                var dealership = repository.Get(id);
                var targets    = provider.Get(dealership, start, end);
                var actuals    = calculator.CalculateFor(dealership, start, end);

                // map from domain to view model so UI is not coupled to domain objects
                // could move this logic into a separate mapper
                statuses.Add(new DealershipPerformanceStatus
                {
                    DealershipName = dealership.Name,
                    TotalRevenue   = actuals.TotalRevenue,
                    TargetRevenue  = targets.TargetRevenue,
                    NetProfit      = actuals.NetProfit,
                    TargetProfit   = targets.TargetProfit
                });
            }
            return(statuses);
        }
Exemple #2
0
        private List <DealershipPerformanceStatus> BuildStatuses(IEnumerable <Dealership> dealerships, DateTime start, DateTime end)
        {
            var statuses = new List <DealershipPerformanceStatus>();

            foreach (var dealership in dealerships)
            {
                var status   = new DealershipPerformanceStatus();
                var mediator = new DealershipAssessmentMediator(status); // Mediator wraps status

                var targets = provider.Get(dealership, start, end);
                var actuals = calculator.CalculateFor(dealership, start, end);

                // pass in the mediator, so private data can be set on the media
                targets.Populate(mediator);
                actuals.Populate(mediator);

                statuses.Add(status); // values will have been set by the mediator when passed into domain objects
            }
            return(statuses);
        }