private string OrderAdminTabString(int orderId, IHtmlHelper helper) { var order = _orderService.GetOrderById(orderId); var setting = _settingService.LoadSetting <CcSettings>(); var fileNameTemplate = setting.DesignFileName; if (fileNameTemplate == null) { fileNameTemplate = ""; } var flag = false; var model = new CcOrderModel(); foreach (var item in order.OrderItems) { model.Items.Add(item); var ccResult = _ccService.GetCcResult(item.AttributesXml); if (ccResult != null) { var fileName = _ccService.FormatOrderTokenString(item, fileNameTemplate); ccResult.HiResOutputName = fileName; model.CcResult.Add(ccResult); flag = true; } } var content = ""; if (flag) { content = helper.Partial("~/Plugins/Widgets.CustomersCanvas/Views/Order/OrderAdminTab.cshtml", model).RenderHtmlContent(); content = JavaScriptEncoder.Default.Encode(content); } return(content); }
public ActionResult Export(string selectedIds) { var allowExportOrdersPDF = "true"; //System.Configuration.ConfigurationManager.AppSettings["IsAllowExportOrdersPDF"]; if (allowExportOrdersPDF != "false") { var orders = new List <Core.Domain.Orders.Order>(); if (selectedIds != null) { var ids = selectedIds .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => Convert.ToInt32(x)) .ToArray(); orders.AddRange(_orderService.GetOrdersByIds(ids)); } if (orders.Count > 0) { var customersCanvasSettings = _settingService.LoadSetting <CcSettings>(); var fileNameTemplate = customersCanvasSettings.DesignFileName; if (fileNameTemplate == null) { fileNameTemplate = ""; } var path = customersCanvasSettings.OrderExportPath; if (string.IsNullOrEmpty(path)) { ErrorNotification(_localizationService.GetResource("Plugins.Widgets.CustomersCanvas.OrderExportPathWarning")); } else { var designResults = new List <Tuple <string, string, int> >(); foreach (var order in orders) { for (var i = 0; i < order.OrderItems.Count; i++) { var item = order.OrderItems.ElementAt(i); var index = i; if (order.OrderItems.Count == 1) { index = -1; } var ccResult = _ccService.GetCcResult(item.AttributesXml); if (ccResult != null) { var fileName = _ccService.FormatOrderTokenString(item, fileNameTemplate); var curPath = _ccService.FormatOrderTokenString(item, path); if (!Directory.Exists(curPath)) { Directory.CreateDirectory(curPath); } curPath += @"\" + fileName; if (fileNameTemplate.IndexOf("<item_index>") == -1 && fileNameTemplate.IndexOf("<item_guid>") == -1 && index != -1) { curPath += "_" + index; } curPath += ".pdf"; foreach (var url in ccResult.HiResUrls) { designResults.Add(new Tuple <string, string, int>(url, curPath, item.OrderId)); } } } } if (designResults.Count > 0) { var isError = false; // TODO paraller foreach (var x in designResults) { var url = x.Item1; var filePath = x.Item2; var orderId = x.Item3; try { new WebClient().DownloadFile(url, filePath); } catch (Exception ex) { isError = true; _logger.Error("Error to export pdf in order id=" + orderId.ToString() + " \r\n from " + url + " \r\n to " + filePath, ex); } } if (isError) { ErrorNotification(_localizationService.GetResource("Plugins.Widgets.CustomersCanvas.OrderExportDownloadError")); } else { SuccessNotification(_localizationService.GetResource("Plugins.Widgets.CustomersCanvas.OrderExportFinish")); } } else { WarningNotification(_localizationService.GetResource("Plugins.Widgets.CustomersCanvas.OrderExportEmpty")); } } } else { WarningNotification(_localizationService.GetResource("Admin.Orders.PdfInvoice.NoOrders")); } } else { WarningNotification("Export is not allowed on this site."); } return(Redirect(Request.Headers["Referer"].ToString())); }