Exemplo n.º 1
0
        public static IEnumerable <Expression <Func <SalesTerritory, SalesTerritoryReturn> > > SplitSelectSalesTerritory(AdventureWorksContext context)
        {
            var contact = ContactProjectors.SelectContact();
            var splitSelectCustomerOrders = CustomerProjectors.SplitSelectCustomerOrders(context);

            return(new Projectors <SalesTerritory, SalesTerritoryReturn>
            {
                //t => new SalesTerritoryReturn
                //    {
                //        Name = t.Name,
                //        CountryRegionCode = t.CountryRegionCode,
                //        Group = t.Group,
                //        Provinces = t.StateProvinces.Select(p => p.Name),
                //    },
                //t => new SalesTerritoryReturn
                //    {
                //        SalesPeople = t.SalesPersons.Select(p => contact.Invoke(p.Employee.Contact))
                //    },
                //t => new SalesTerritoryReturn
                //    {
                //        SalesPeopleHistory = t.SalesTerritoryHistories.Select(h => contact.Invoke(h.SalesPerson.Employee.Contact))
                //    },
                { splitSelectCustomerOrders, p => t => new SalesTerritoryReturn
                  {
                      //SalesOrders = t.SalesPersons.SelectMany(r => r.Stores.Select(e => p.Invoke(e.Customer))),
                      SalesOrders = t.Customers.Where(c => c.CustomerType == "S").Select(u => p.Invoke(u)),
                  } }
            });
        }
Exemplo n.º 2
0
        public static IEnumerable <Expression <Func <SalesOrderHeader, SalesOrderReturn> > > SplitSelectOrder(AdventureWorksContext context)
        {
            var detail  = SalesOrderDetailProjectors.SplitSelectOrderDetail(context);
            var contact = ContactProjectors.SelectContact();

            return(new Projectors <SalesOrderHeader, SalesOrderReturn>
            {
                h => new SalesOrderReturn
                {
                    SalesOrderNumber = h.SalesOrderNumber,
                    PurchaseOrderNumber = h.PurchaseOrderNumber,
                    AccountNumber = h.AccountNumber,
                    ShipMethod = h.ShipMethod.Name,
                    Reasons = h.SalesOrderHeaderSalesReasons.Select(r => r.SalesReason.Name),
                },
                h => new SalesOrderReturn
                {
                    SalesPerson = contact.Invoke(h.SalesPerson.Employee.Contact),
                    TotalValue = h.SalesOrderDetails.Any() ? h.SalesOrderDetails.Sum(s => s.OrderQty * (s.UnitPrice * ((decimal)1.0 - s.UnitPriceDiscount))) : (decimal)0.0,
                },
                { detail, p => h => new SalesOrderReturn
                  {
                      Details = h.SalesOrderDetails.Select(d => p.Invoke(d))
                  } }
            });
        }
        public static IEnumerable <Expression <Func <Customer, CustomerOrdersReturn> > > SplitSelectCustomerOrders(AdventureWorksContext context)
        {
            var splitSelectOrder = SalesOrderProjectors.SplitSelectOrder(context);
            var address          = AddressProjectors.SelectAddress();
            var contact          = ContactProjectors.SelectContact();

            return(new Projectors <Customer, CustomerOrdersReturn>
            {
                c => new CustomerOrdersReturn
                {
                    AccountNumber = c.AccountNumber,
                    Type = c.CustomerType,
                    Contact = contact.Invoke(c.Individual.Contact),
                    Addresses = c.CustomerAddresses.Select(a => address.Invoke(a.Address)),
                },
                { splitSelectOrder, p => c => new CustomerOrdersReturn
                  {
                      Orders = c.SalesOrderHeaders.Select(o => p.Invoke(o))
                  } }
            });
        }
        public static IEnumerable <Expression <Func <Employee, EmployeeSalesReturn> > > SelectSales(AdventureWorksContext context)
        {
            var contact     = ContactProjectors.SelectContact();
            var sales       = SalesOrderProjectors.SplitSelectOrder(context);
            var territories = SalesTerritoryProjector.SplitSelectSalesTerritory(context);

            return(new Projectors <Employee, EmployeeSalesReturn>
            {
                e => new EmployeeSalesReturn
                {
                    Contact = contact.Invoke(e.Contact)
                },
                { sales, p => e => new EmployeeSalesReturn
                  {
                      Orders = e.SalesPerson.SalesOrderHeaders.Select(o => p.Invoke(o))
                  } },
                { territories, p => e => new EmployeeSalesReturn
                  {
                      TerritorySales = new [] { e.SalesPerson.SalesTerritory }.Select(t => p.Invoke(t)).FirstOrDefault()
                  } }
            });
        }