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)); }
public void EnrichWithExternalData(PageXml content, PageData externalData, IRepository repository, ICrmService crmService, int salesOrders, bool addCustomerDetails, ILocationService locationService) { // enrich with externalData other than customer if (externalData.CustomerData != null) { // enrich with externalData.CustomerData } else { CustomerInfo customerData = crmService.GetCustomerInfo(content.Customer.Name); } if (salesOrders > 0) { var orders = repository.GetEntities <Order>() .Where(o => o.Customer.CompanyName == content.Customer.Name) .OrderBy(o => o.OrderDate) .Take(salesOrders); //enrich with orders } }
public PageXml GetPageForOrders(IEnumerable <Order> orders, ICrmService crmService, ILocationService locationService) { string customerName = GetCustomerNameFromFirstOrder(); PageXml content = new PageXml { Customer = new CustomerXml { Name = customerName } }; if (crmService != null) { CustomerInfo customerData = crmService.GetCustomerInfo(content.Customer.Name); //enrich with data from crm } //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); } } } return(content); }
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); } }
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); }