Exemplo n.º 1
0
        public string WriteOutputToJson(ReportingDto ceo)
        {
            var options = new JsonSerializerSettings
            {
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore
            };

            return(JsonConvert.SerializeObject(ceo, options));
        }
Exemplo n.º 2
0
        public void GetsAnyReportingEmployees()
        {
            var service = new ReportingService();
            var manager = new Employee {
                Id = 100, Name = "Alan", ManagerId = 150
            };

            var reportingManager = new ReportingDto(manager);

            service.GetReportingEmployees(reportingManager);

            Assert.Equal(2, reportingManager.Employees.Count);
            Assert.Equal("Martin", reportingManager.Employees.First().Name);
            Assert.Equal("Alex", reportingManager.Employees.Last().Name);
        }
Exemplo n.º 3
0
        public ReportingDto GetReportingEmployees(ReportingDto manager)
        {
            manager.Employees = new List <ReportingDto>();
            var employeesReporting = InMemoryDatabase.Employees().Where(a => a.ManagerId == manager.Id).ToList();

            if (employeesReporting.Count == 0)
            {
                manager.Employees = null;
                return(manager);
            }

            foreach (var employee in employeesReporting)
            {
                manager.Employees.Add(new ReportingDto(employee));
            }

            return(manager);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> GetReport([FromBody] ReportingDto reportingData)
        {
            var reportingUtils = new ReportingUtils();
            var reportType     = reportingData.ReportType != null ? (OutputPresentationType)reportingData.ReportType.Value : OutputPresentationType.PDF;
            var reportStream   = reportingUtils.GetReport(reportingData.TemplateName, reportingData.ParamList, reportType);

            switch (reportType)
            {
            case OutputPresentationType.HTML:     //html 0
            case OutputPresentationType.XML:      //xml 4
            case OutputPresentationType.ASPHTML:  //ASPHTML 5
            case OutputPresentationType.Internal: //Internal 6
            case OutputPresentationType.MHTML:    //MHTML 7
            case OutputPresentationType.CSV:      //CSV 8
                return(new ObjectResult(reportStream));

            case OutputPresentationType.RenderPdf_iTextSharp: //pdf_itext 1
            case OutputPresentationType.PDF:                  //pdf 2
            case OutputPresentationType.PDFOldStyle:          //PDFOldStyle 3
                return(new FileStreamResult(reportStream, "application/pdf"));

            case OutputPresentationType.RTF:     //RTF 9
                return(new FileStreamResult(reportStream, "application/rtf"));

            case OutputPresentationType.Word:     //word 10
                return(new FileStreamResult(reportStream, "application/vnd.ms-word"));

            case OutputPresentationType.Excel:     //Excel 11
                return(new FileStreamResult(reportStream, "application/vnd.ms-excel"));

            case OutputPresentationType.TIF:     //TIF 12
            case OutputPresentationType.TIFBW:   //TIFBW 13
                return(new FileStreamResult(reportStream, "image/tiff"));

            case OutputPresentationType.Excel2003:     //Excel2003 14
                return(new FileStreamResult(reportStream, "application/vnd.ms-excel"));
            }

            return(new FileStreamResult(reportStream, "application/pdf"));
        }
Exemplo n.º 5
0
        public void WritesOutputToJsonTest()
        {
            var manager = new Employee {
                Id = 100, Name = "Jamie", ManagerId = 0
            };
            var employee = new Employee {
                Id = 100, Name = "Alex", ManagerId = 150
            };

            var dto = new ReportingDto(manager)
            {
                Name      = "Jamie",
                Employees = new List <ReportingDto> {
                    new ReportingDto(employee)
                }
            };

            var service    = new ReportingService();
            var jsonOutput = service.WriteOutputToJson(dto);

            Assert.NotNull(jsonOutput);
        }