Exemple #1
0
        public ActionResult ExportShipmentInvoice(int typeId, string ids)
        {
            try
            {
                //_logHelper.Info($"request {ids}");
                string     fileName      = "";
                List <int> lstShipmentId = new List <int>();
                if (!string.IsNullOrEmpty(ids))
                {
                    var lstId = ids.Split(',');
                    int id    = 0;
                    foreach (var i in lstId)
                    {
                        if (!string.IsNullOrEmpty(i))
                        {
                            int.TryParse(i, out id);
                            if (id != 0)
                            {
                                lstShipmentId.Add(id);
                            }
                        }
                    }
                    if (lstShipmentId.Any())
                    {
                        fileName = string.Format("{0} - {1} - Invoice shipment.xlsx", DateTime.Today.ToString("yyyyMMdd"), fileName);
                        var          lstShipment = _shipmentService.Admin_ExportShipmentByLstId(lstShipmentId);
                        MemoryStream ms          = null;
                        switch (typeId)
                        {
                        case 1:     // USA
                            ms = ExportTemplateUSA(lstShipment);
                            break;

                        case 2:     // VN
                            ms = ExportTemplateVN(lstShipment);
                            break;
                        }
                        ms.WriteTo(Response.OutputStream);
                        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                        Response.AddHeader("content-disposition", "attachment;  filename=" + fileName);
                        ms.Close();
                        return(new EmptyResult());
                    }
                }
            }
            catch (Exception ex)
            {
                string test = ex.Message;
                _logHelper.Info(ex);
            }
            return(RedirectToAction("Manager"));
        }