コード例 #1
0
        public bool ExportCustomerPage(string customerName)
        {
            PageXml content = new PageXml {
                Customer = new CustomerXml {
                    Name = customerName
                }
            };

            using (EfRepository repository = new EfRepository())
            {
                if (maxSalesOrders > 0)
                {
                    var orders = repository.GetEntities <Order>()
                                 .Where(o => o.Customer.CompanyName == content.Customer.Name)
                                 .OrderBy(o => o.OrderDate)
                                 .Take(maxSalesOrders);

                    //enrich content with orders
                    // ...
                }

                if (addCustomerDetails)
                {
                    var customer = repository.GetEntities <Customer>()
                                   .Where(c => c.CompanyName == customerName);

                    // enrich content with customer data
                    // ...
                }
            }

            return(fileWriter.WriteFile(content, "CustomerPage"));
        }
コード例 #2
0
        public bool ExportOrders(string customerName)
        {
            string fileName = string.Format(fileNameFormat, "CustomerOrdersPage", customerName, DateTime.Now);
            string filePath = Path.Combine(exportFolder, fileName);

            if (!overwrite && File.Exists(filePath))
            {
                return(false);
            }

            PageXml content = new PageXml {
                Customer = new CustomerXml {
                    Name = customerName
                }
            };

            using (EfRepository repository = new EfRepository())
            {
                var orders = repository.GetEntities <Order>()
                             .Where(o => o.Customer.CompanyName == content.Customer.Name)
                             .OrderBy(o => o.ApprovedAmmount)
                             .ThenBy(o => o.OrderDate);

                //enrich content with orders
            }

            XmlSerializer serializer = new XmlSerializer(typeof(PageXml));

            using (StreamWriter sw = File.CreateText(filePath))
            {
                serializer.Serialize(sw, content);
            }
            return(true);
        }
コード例 #3
0
        public bool ExportCustomerPageWithExternalData(
            string customerName,
            PageData externalData)

        {
            PageXml content = new PageXml {
                Customer = new CustomerXml {
                    Name = customerName
                }
            };

            if (externalData.CustomerData != null)
            {
                // enrich with externalData.CustomerData
                // ...
            }
            else
            {
                CustomerInfo customerData = crmService.GetCustomerInfo(content.Customer.Name);
            }

            using (EfRepository repository = new EfRepository())
            {
                if (maxSalesOrders > 0)
                {
                    var orders = repository.GetEntities <Order>()
                                 .Where(o => o.Customer.CompanyName == content.Customer.Name)
                                 .OrderBy(o => o.OrderDate)
                                 .Take(maxSalesOrders);

                    //enrich content with orders
                    // ...
                }

                if (addCustomerDetails)
                {
                    var customer = repository.GetEntities <Customer>()
                                   .Where(c => c.CompanyName == customerName);

                    // enrich content by merging the external customer data with what read from DB
                    // ...
                }
            }

            if (locationService != null)
            {
                foreach (var address in content.Customer.Addresses)
                {
                    Coordinates coordinates = locationService.GetCoordinates(address.City, address.Street, address.Number);
                    if (coordinates != null)
                    {
                        address.Coordinates = string.Format("{0},{1}", coordinates.Latitude, coordinates.Longitude);
                    }
                }
            }

            return(fileWriter.WriteFile(content));
        }
コード例 #4
0
        public bool ExportCustomerPage(
            string fileNameFormat,
            bool overwrite,
            string customerName,
            int maxSalesOrders,
            bool addCustomerDetails)
        {
            string fileName = string.Format(fileNameFormat, "CustomerPage", customerName, DateTime.Now); // fileNameFormat = "{0}_{1}_{2}.xml"
            string filePath = Path.Combine(exportFolder, fileName);

            if (!overwrite && File.Exists(filePath))
            {
                return(false);
            }


            PageXml content = new PageXml {
                Customer = new CustomerXml {
                    Name = customerName
                }
            };

            using (EfRepository repository = new EfRepository())
            {
                if (maxSalesOrders > 0)
                {
                    var orders = repository.GetEntities <Order>()
                                 .Where(o => o.Customer.CompanyName == customerName)
                                 .OrderBy(o => o.OrderDate)
                                 .Take(maxSalesOrders);

                    //enrich content with orders
                    // ...
                }

                if (addCustomerDetails)
                {
                    var customer = repository.GetEntities <Customer>()
                                   .Where(c => c.CompanyName == customerName);

                    // enrich content with customer data
                    // ...
                }
            }


            XmlSerializer serializer = new XmlSerializer(typeof(PageXml));

            using (StreamWriter sw = File.CreateText(filePath))
            {
                serializer.Serialize(sw, content);
            }
            return(true);
        }
コード例 #5
0
        public bool ExportOrders(string customerName)
        {
            PageXml content = new PageXml {
                Customer = new CustomerXml {
                    Name = customerName
                }
            };

            IEnumerable <CustomerData> orders = dataProvider.GetCustomerOrders(customerName);

            //enrich content with orders

            return(fileWriter.WriteFile(content));
        }
コード例 #6
0
        public IEnumerable <PageXml> GetPagesFromOrders(
            IEnumerable <Order> orders,
            int maxSalesOrders,
            ICrmService crmService,
            ILocationService locationService)
        {
            Dictionary <string, IEnumerable <Order> > customerOrders = GroupOrdersByCustomer(orders);

            foreach (var customerName in customerOrders.Keys)
            {
                PageXml content = new PageXml {
                    Customer = new CustomerXml {
                        Name = customerName
                    }
                };

                if (crmService != null)
                {
                    CustomerInfo customerData = crmService.GetCustomerInfo(content.Customer.Name);
                    //enrich with data from crm
                }

                var recentOrders = customerOrders[customerName]
                                   .OrderBy(o => o.OrderDate)
                                   .Take(maxSalesOrders);
                foreach (var order in recentOrders)
                {
                    // enrich content with orders
                    // ...
                }

                if (locationService != null)
                {
                    foreach (var address in content.Customer.Addresses)
                    {
                        Coordinates coordinates = locationService.GetCoordinates(address.City, address.Street, address.Number);
                        if (coordinates != null)
                        {
                            address.Coordinates = string.Format("{0},{1}", coordinates.Latitude, coordinates.Longitude);
                        }
                    }
                }

                yield return(content);
            }
        }
コード例 #7
0
        public bool ExportOrders(string customerName)
        {
            PageXml content = new PageXml {
                Customer = new CustomerXml {
                    Name = customerName
                }
            };

            using (EfRepository repository = new EfRepository())
            {
                var orders = repository.GetEntities <Order>()
                             .Where(o => o.Customer.CompanyName == content.Customer.Name)
                             .OrderBy(o => o.ApprovedAmmount)
                             .ThenBy(o => o.OrderDate);

                //enrich content with orders
            }

            return(fileWriter.WriteFile(content));
        }
コード例 #8
0
        public bool ExportCustomerPageWithExternalData(
            string customerName,
            PageData externalData)

        {
            PageXml content = new PageXml {
                Customer = new CustomerXml {
                    Name = customerName
                }
            };

            if (externalData.CustomerData != null)
            {
                // enrich with externalData.CustomerData
                // ...
            }
            else
            {
                CustomerInfo customerData = dataProvider.GetCustomerInfo(content.Customer.Name);
            }

            IEnumerable <CustomerData> orders = dataProvider.GetCustomerOrders(customerName);

            // enrich content with orders
            // ...

            // enrich content by merging the external customer data with what read from DB
            // ...

            foreach (var address in content.Customer.Addresses)
            {
                Coordinates coordinates = locationService.GetCoordinates(address.City, address.Street, address.Number);
                if (coordinates != null)
                {
                    address.Coordinates = string.Format("{0},{1}", coordinates.Latitude, coordinates.Longitude);
                }
            }

            return(fileWriter.WriteFile(content));
        }
コード例 #9
0
        public bool ExportCustomerPageWithExternalData(
            string customerName,
            PageData externalData,
            ICrmService crmService,
            ILocationService locationService)
        {
            string fileName = string.Format("{0}-{1}.xml", fileNameFormat, customerName);
            string filePath = Path.Combine(exportFolder, fileName);

            if (!overwrite && File.Exists(filePath))
            {
                return(false);
            }


            PageXml content = new PageXml {
                Customer = new CustomerXml {
                    Name = customerName
                }
            };

            if (externalData.CustomerData != null)
            {
                // enrich with externalData.CustomerData
                // ...
            }
            else
            {
                CustomerInfo customerData = crmService.GetCustomerInfo(content.Customer.Name);
            }

            using (EfRepository repository = new EfRepository())
            {
                if (maxSalesOrders > 0)
                {
                    var orders = repository.GetEntities <Order>()
                                 .Where(o => o.Customer.CompanyName == content.Customer.Name)
                                 .OrderBy(o => o.OrderDate)
                                 .Take(maxSalesOrders);

                    //enrich content with orders
                    // ...
                }

                if (addCustomerDetails)
                {
                    var customer = repository.GetEntities <Customer>()
                                   .Where(c => c.CompanyName == customerName);

                    // enrich content by merging the external customer data with what read from DB
                    // ...
                }
            }

            if (locationService != null)
            {
                foreach (var address in content.Customer.Addresses)
                {
                    Coordinates coordinates = locationService.GetCoordinates(address.City, address.Street, address.Number);
                    if (coordinates != null)
                    {
                        address.Coordinates = string.Format("{0},{1}", coordinates.Latitude, coordinates.Longitude);
                    }
                }
            }


            XmlSerializer serializer = new XmlSerializer(typeof(PageXml));

            using (StreamWriter sw = File.CreateText(filePath))
            {
                serializer.Serialize(sw, content);
            }
            return(true);
        }