private static void SalesReportTest() { FakeOrdersService ordersService = new FakeOrdersService(); IEnumerable <Order> orders = ordersService.Get(); SalesReport salesReport = new SalesReport(); // Header salesReport.Title = "Raport sprzedaży"; salesReport.CreateDate = DateTime.Now; salesReport.TotalSalesAmount = orders.Sum(s => s.Amount); // By Gender salesReport.GenderDetails = orders .GroupBy(o => o.Customer.Gender) .Select(g => new GenderReportDetail( g.Key, g.Sum(x => x.Details.Sum(d => d.Quantity)), g.Sum(x => x.Details.Sum(d => d.LineTotal)))); // By Product salesReport.ProductDetails = orders .SelectMany(o => o.Details) .GroupBy(o => o.Product) .Select(g => new ProductReportDetail(g.Key, g.Sum(p => p.Quantity), g.Sum(p => p.LineTotal))); Console.WriteLine(salesReport); }
public SalesReport Build() { SalesReport salesReport = new SalesReport(); // Header if (!string.IsNullOrEmpty(title)) { salesReport.Title = title; salesReport.CreateDate = DateTime.Now; salesReport.TotalSalesAmount = orders.Sum(s => s.Amount); } // Section By Gender if (hasSectionByGender) { salesReport.GenderDetails = orders .GroupBy(o => o.Customer.Gender) .Select(g => new GenderReportDetail( g.Key, g.Sum(x => x.Details.Sum(d => d.Quantity)), g.Sum(x => x.Details.Sum(d => d.LineTotal)))); } // Section By Product if (hasSectionByProduct) { salesReport.ProductDetails = orders .SelectMany(o => o.Details) .GroupBy(o => o.Product) .Select(g => new ProductReportDetail(g.Key, g.Sum(p => p.Quantity), g.Sum(p => p.LineTotal))); } return(salesReport); }
// Create product public SalesReportBase Build() { SalesReport salesReport = new SalesReport(); if (hasHeader) { salesReport.Title = "Raport sprzedaży"; salesReport.CreateDate = DateTime.Now; salesReport.TotalSalesAmount = orders.Sum(s => s.Amount); } if (hasGenderTotals) { salesReport.GenderDetails = orders .GroupBy(o => o.Customer.Gender) .Select(g => new GenderReportDetail( g.Key, g.Sum(x => x.Details.Sum(d => d.Quantity)), g.Sum(x => x.Details.Sum(d => d.LineTotal)))); } if (hasProductTotals) { salesReport.ProductDetails = orders .SelectMany(o => o.Details) .GroupBy(o => o.Product) .Select(g => new ProductReportDetail(g.Key, g.Sum(p => p.Quantity), g.Sum(p => p.LineTotal))); } return(salesReport); }
public SalesReport Build() { SalesReport result = salesReport; salesReport = null; return(result); }
private static void SalesReportBuilderTest() { FakeOrdersService ordersService = new FakeOrdersService(); IEnumerable <Order> orders = ordersService.Get(); ISalesReportBuilder salesReportBuilder = new SalesReportBuilder(orders); salesReportBuilder.AddHeader(); salesReportBuilder.AddSectionByGender(); salesReportBuilder.AddSectionByProduct(); SalesReport salesReport = salesReportBuilder.Build(); }
private static void SalesReportTest() { FakeOrdersService ordersService = new FakeOrdersService(); IEnumerable <Order> orders = ordersService.Get(); ISalesReportBuilder salesReportBuilder = new MySalesReportBuilder(orders); salesReportBuilder.AddHeader("Raport sprzedaży"); salesReportBuilder.AddSectionByGender(); salesReportBuilder.AddSectionByProduct(); SalesReport salesReport = salesReportBuilder.Build(); Console.WriteLine(salesReport); }
public SalesReport Build() { SalesReport salesReport = new SalesReport(); if (hasHeader) { CreateHeader(salesReport); } if (hasSectionByGender) { } return(salesReport); }
private static void SalesReportTest() { FakeOrdersService ordersService = new FakeOrdersService(); IEnumerable <Order> orders = ordersService.Get(); ISalesReportBuilder salesReportBuilder = new SalesReportBuilder(orders); salesReportBuilder.AddHeader(); if (true) { salesReportBuilder.AddSectionByGender(); } salesReportBuilder.AddSectionByProduct(); SalesReport salesReport = salesReportBuilder.Build(); //SalesReport salesReport = new SalesReport(); //salesReport.Title = "Raport sprzedaży"; //salesReport.CreateDate = DateTime.Now; //salesReport.TotalSalesAmount = orders.Sum(s => s.Amount); //salesReport.GenderDetails = orders // .GroupBy(o => o.Customer.Gender) // .Select(g => new GenderReportDetail( // g.Key, // g.Sum(x => x.Details.Sum(d => d.Quantity)), // g.Sum(x => x.Details.Sum(d => d.LineTotal)))); //salesReport.ProductDetails = orders // .SelectMany(o => o.Details) // .GroupBy(o => o.Product) // .Select(g => new ProductReportDetail(g.Key, g.Sum(p => p.Quantity), g.Sum(p => p.LineTotal))); Console.WriteLine(salesReport); }
private static void SalesReportTest() { bool hasSectionByGender = true; FakeOrdersService ordersService = new FakeOrdersService(); IEnumerable <Order> orders = ordersService.Get(); ISalesReportBuilder salesReportBuilder = new MySalesReportBuilder(orders); salesReportBuilder.AddHeader(); if (hasSectionByGender) { salesReportBuilder.AddSectionByGender(); } salesReportBuilder.AddSectionByProduct(); SalesReport salesReport = salesReportBuilder.Build(); Console.WriteLine(salesReport); }
private SalesReportBuilder() { salesReport = new SalesReport(); }
public SalesReportBuilder(IEnumerable <Order> orders) { this.orders = orders; salesReport = new SalesReport(); }
private void CreateHeader(SalesReport salesReport) { salesReport.Title = "Raport sprzedaży"; salesReport.CreateDate = DateTime.Now; salesReport.TotalSalesAmount = orders.Sum(s => s.Amount); }