/// <summary>
        /// Generates a new TopTotalRevenueByDealerReport.
        /// </summary>
        public void Generate(IDocumentAdapter document, ICarsFactoryDbContext dbContext)
        {
            var totalRevenueByDealers = (from dealer in dbContext.Dealers
                                         let totalRevenue =
                                             (decimal?)dealer.Cars.Where(
                                                 y =>
                                                 y.OrderId != null &&
                                                 y.Order.OrderStatus == OrderStatus.Closed)
                                             .Sum(x => x.Price)
                                             let town = dealer.Town.Name
                                                        let orderCount =
                                                 dealer.Cars.Count(
                                                     y =>
                                                     y.OrderId != null &&
                                                     y.Order.OrderStatus == OrderStatus.Closed)
                                                 orderby totalRevenue descending
                                                 select new
            {
                Dealer = dealer.Name,
                TotalRevenue = totalRevenue,
                Town = town,
                TotalOrders = orderCount
            })
                                        .Take(10)
                                        .ToList();

            document.AddMetadata()
            .AddHeader($"Top 10 total revenue by dealer for all time. Generated on {DateTime.Now}")
            .AddTabularData(totalRevenueByDealers)
            .Save();
        }
Beispiel #2
0
        /// <summary>
        /// Generates a new TotalRevenueInLastYearByDealerReport.
        /// </summary>
        public void Generate(IDocumentAdapter document, ICarsFactoryDbContext dbContext)
        {
            var lastYear = DateTime.Now.Year - 1;
            var totalRevenueForThePastMonth = (from dealer in dbContext.Dealers
                                               let totalRevenue =
                                                   (decimal?)dealer.Cars.Where(
                                                       car =>
                                                       car.Order != null &&
                                                       car.Order.Date.Year > lastYear &&
                                                       car.Order.OrderStatus == OrderStatus.Closed)
                                                   .Sum(c => c.Price)
                                                   let town = dealer.Town.Name
                                                              let orderCount = dealer.Cars.Count(car => car.Order != null &&
                                                                                                 car.Order.Date.Year > lastYear &&
                                                                                                 car.Order.OrderStatus == OrderStatus.Closed)
                                                                               orderby totalRevenue descending
                                                                               select new
            {
                Dealer = dealer.Name,
                TotalRevenue = totalRevenue,
                Town = town,
                TotalOrders = orderCount
            })
                                              .ToList();

            document.AddMetadata()
            .AddHeader($"Total revenue by dealer for the last year. Generated on {DateTime.Now}")
            .AddTabularData(totalRevenueForThePastMonth)
            .Save();
        }
        public void Generate(IDocumentAdapter document)
        {
            var fakeDb = new MockDbContext();

            using (fakeDb)
            {
                var totalRevenueByDealers = fakeDb.GetTotalRevenueByDealers();

                document.AddMetadata()
                .AddRow($"Top 10 total revenue by dealer for all time. Generated on {DateTime.Now}")
                .AddTable(totalRevenueByDealers)
                .Save();
            }
        }
        /// <summary>
        /// Generates a new DealerSalesReportForLastQuarter.
        /// </summary>
        public void Generate(IDocumentAdapter document, ICarsFactoryDbContext dbContext)
        {
            var pastDate = DateTime.Now.AddMonths(-3);

            Console.WriteLine(dbContext.Orders.First().TotalPrice);

            var dealerData = (from dealer in dbContext.Dealers
                              let cars = dealer.Cars.Where(car => car.OrderId != null &&
                                                           car.Order.OrderStatus == OrderStatus.Closed &&
                                                           car.Order.Date > pastDate)
                                         .Select(c => new
            {
                Model = c.Model.Manufacturer.Name + " " + c.Model.Name,
                Year = c.Year.Year,
                Price = c.Price,
                OrderDate = c.Order.Date,
                OrderId = c.OrderId
            })
                                         select new
            {
                Cars = cars.ToList(),
                Name = dealer.Name,
                Town = dealer.Town.Name,
            }
                              ).OrderByDescending(x => x.Cars.Count)
                             .ToList();

            document.AddMetadata()
            .AddHeader($"Dealer sales report for the last three months. Generated on {DateTime.Now}");

            foreach (var dealer in dealerData)
            {
                var deal = new { Dealer = dealer.Name + ", " + dealer.Town };
                var dealerTableData = new[] { deal }.ToList();
                document.AddTabularData(dealerTableData);

                if (dealer.Cars.Count > 0)
                {
                    document.AddTabularData(dealer.Cars);
                }

                var totalsTableData = new { TotalRevenue = dealer.Cars.Sum(c => c.Price) };
                var totals = new[] { totalsTableData }.ToList();
                document.AddTabularData(totals);
                document.AddHeader(string.Empty);
            }

            document.Save();
        }
        /// <summary>
        /// Generates a new TopRevenueByTownReport.
        /// </summary>
        public void Generate(IDocumentAdapter document, ICarsFactoryDbContext dbContext)
        {
            var topTowns = (from car in
                            dbContext.Cars
                            .Where(car => car.OrderId != null && car.Order.OrderStatus == OrderStatus.Closed)
                            group car by car.Dealer.Town.Name
                            into g
                            orderby g.Count() descending
                            select new
            {
                Town = g.Key,
                OrderCount = g.Count()
            })
                           .ToList();

            document.AddMetadata()
            .AddHeader($"Most orders by town. Generated on {DateTime.Now}")
            .AddTabularData(topTowns)
            .Save();
        }
        /// <summary>
        /// Generates a new TopSellingManufacturersReport.
        /// </summary>
        public void Generate(IDocumentAdapter document, ICarsFactoryDbContext dbContext)
        {
            var topManufacturers =
                (from car in
                 dbContext.Cars.Where(car => car.OrderId != null && car.Order.OrderStatus == OrderStatus.Closed)
                 group car by car.Model.Manufacturer.Name
                 into g
                 orderby g.Count() descending
                 select new
            {
                Model = g.Key,
                OrderCount = g.Count()
            })
                .ToList();

            document.AddMetadata()
            .AddHeader($"Top selling manufacturers of all time. Generated on {DateTime.Now}")
            .AddTabularData(topManufacturers)
            .Save();
        }