public IHttpActionResult DownloadWarehousePreviewReport([FromUri] OrderAdminSearchCriteria searchCriteria, [FromUri] OrderType orderType) { try { var template = orderType == OrderType.Cash ? _appSettings.WarehousePackageDiscountOrderTemplate : _appSettings.WarehousePackagePVOrderTemplate; var path = System.Web.Hosting.HostingEnvironment.MapPath(template); byte[] content = {}; using (var file = File.Open(path, FileMode.Open)) { searchCriteria.OrderStatus = OrderStatus.Approved; switch (orderType) { case OrderType.PV: content = _orderReportService.GetWarehousePackagePVOrderReport(_workContext.User, file, searchCriteria, true); break; case OrderType.Cash: content = _orderReportService.GetWarehousePackageDiscountOrderReport(_workContext.User, file, searchCriteria, true); break; default: content = _orderReportService.GetWarehousePackageReport(_workContext.User, file, searchCriteria); break; } } var stream = new MemoryStream(content); var result = new HttpExtension.FileActionResult(stream, $"WarehouseOrderPreviewReport_{orderType}_{DateTime.Now.ToString("dd-MM-yyyy")}.xlsx"); return(result); } catch (StaffingPurchaseException ex) { return(new HttpExtension.StaffPurchaseExceptionActionResult(ex.Message)); } catch (Exception ex) { _logger.Error("Failed to download Warehouse Preview Report", ex); return(new HttpExtension.StaffPurchaseExceptionActionResult(_resourceManager.GetString("OrderReport.FailedToReport"))); } }