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));
        }
Exemple #2
0
        public bool ExportOrders(
            string fileNameFormat,
            bool overwrite,
            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);
        }
Exemple #3
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);
        }