mercredi 22 février 2017

How to get FileStreamResult Output

I have a program I'm modifying that is basically a delivery schedule website using ASP.NET MVC3. The addition I'm giving the site is the ability to print a manifest (it can already print a delivery schedule) but I've run into a snag which would be my lack of understanding. Basically I have it setup so when a user pushes the button it makes a call to populate the manifest. All I need to do now is print it to PDF using FileStreamResult (there's a method already in place for this) I'm just not sure how to get the output from my PrintShippingManifest method to return something a FileStreamResult method can use.

I've tried googling and searching this site, but I'm now into information overload and could use some direction.

Here's the PrintShippingManinfest in the controller:

  public JsonResult PrintShippingManifest(int id)
        {
            var _manifest = new List<ShippingManifestRootJSON>();
            FillShippingManifest(_manifest, id);
            return Json(new { result = "success", message = "OK" });
        }
        [HttpPost]

And this method as well:

 private void FillShippingManifest(List<ShippingManifestRootJSON> manifest, int id) //added by Chad
        {
            using (var tx = dbSession.BeginTransaction())
            {
                try
                {
                    var shipItems = dbSession.CreateCriteria<ShippingItem>()
                                .Add(Restrictions.Eq("DeliveryTicket.Id", id))
                                .AddOrder(Order.Asc("DeliveryOrder"))
                                .List<ShippingItem>();

                    foreach (var _item in shipItems)
                    {
                        var _root = manifest.Find(x => x.JobNumber == _item.JobNumber);
                        if (_root == null)
                        {
                            _root = new ShippingManifestRootJSON() { JobNumber = _item.JobNumber, Name = _item.JobName, ID = _item.Id };
                            manifest.Add(_root);
                        }
                        var _manifestItem = Mapper.Map<ShippingManifestSectionJSON>(_item);

                        _root.Add(_manifestItem);
                    }

                    foreach (var _job in manifest)
                    {
                        foreach (var _section in _job.Sections)
                        {
                            FillSectionWithData(_section);
                        }
                    }

                }
                catch (Exception ex)
                {
                    if (tx != null)
                        tx.Rollback();


                }
            }
        }

Aucun commentaire:

Enregistrer un commentaire