Ejemplo n.º 1
0
        public ActionResult Export(string ExportType, string OneSite)
        {
            if (Request.HttpMethod == "POST")
            {
                Dictionary <string, IExport> exporters = new Dictionary <string, IExport> {
                    { "TXT", new ExportTxt(Response) },
                    { "XLS", new ExportXls(Response) },
                    { "PDF", new ExportPdf(Response) }
                };

                IExport exporter = exporters[ExportType];

                bool onlyOneSite;
                try {
                    onlyOneSite = OneSite.Equals("on");
                } catch (NullReferenceException) {
                    onlyOneSite = false;
                }

                exporter.PrepareData(onlyOneSite);

                exporter.Export();

                if (ExportType.Equals("PDF"))
                {
                    return(File((exporter as ExportPdf)._memory, exporter.ContentType, $"{exporter.GetName}.{exporter.Extension}"));
                }
            }

            PrepareViewData();

            return(RedirectToAction("Index"));
        }