Ejemplo n.º 1
0
        public async Task <IActionResult> PdfPackagingSlip(string shipmentId)
        {
            var shipment = await _shipmentService.GetShipmentById(shipmentId);

            if (shipment == null)
            {
                //no shipment found with the specified id
                return(RedirectToAction("List"));
            }

            if (_workContext.CurrentCustomer.IsStaff() && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)
            {
                return(RedirectToAction("List"));
            }

            var order = await _orderService.GetOrderById(shipment.OrderId);

            if (order == null)
            {
                //No order found with the specified id
                return(RedirectToAction("List"));
            }

            //a vendor should have access only to his products
            if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) && !_workContext.CurrentCustomer.IsStaff())
            {
                return(RedirectToAction("List"));
            }

            var shipments = new List <Shipment>
            {
                shipment
            };

            byte[] bytes;
            using (var stream = new MemoryStream())
            {
                await _pdfService.PrintPackagingSlipsToPdf(stream, shipments, _workContext.WorkingLanguage.Id);

                bytes = stream.ToArray();
            }
            return(File(bytes, "application/pdf", string.Format("packagingslip_{0}.pdf", shipment.Id)));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Print packaging slips to PDF
 /// </summary>
 /// <param name="stream">Stream</param>
 /// <param name="shipments">Shipments</param>
 /// <param name="languageId">Language identifier; 0 to use a language used when placing an order</param>
 public void PrintPackagingSlipsToPdf(Stream stream, IList <Shipment> shipments, int languageId = 0)
 {
     _pdfService.PrintPackagingSlipsToPdf(stream, shipments, languageId);
 }