コード例 #1
0
ファイル: ReportManager.cs プロジェクト: melisek/Reporting
        public object GetDiscreetRiportDiagram(ReportDiagramDiscDto diagram)
        {
            Report report = _reportRepository.Get(diagram.ReportGUID);

            if (report == null)
            {
                throw new NotFoundException("Report not found by GUID.");
            }

            DataTable data       = new DataTable();
            string    sql        = $"select {diagram.NameColumn}, {diagram.Aggregation.ToString()} ({diagram.ValueColumn}) as Value from {report.Query.ResultTableName} group by {diagram.NameColumn}";
            string    sourceConn = _cfg.GetConnectionString("DefaultConnection");

            using (SqlConnection conn = new SqlConnection(sourceConn))
            {
                SqlCommand cmd = new SqlCommand(sql, conn);
                conn.Open();
                data.Load(cmd.ExecuteReader());
            }

            List <DiscreetValueDto> result = new List <DiscreetValueDto>();

            foreach (DataRow row in data.Rows)
            {
                result.Add(new DiscreetValueDto
                {
                    Name  = row[diagram.NameColumn].ToString(),
                    Value = double.Parse(row["Value"].ToString())
                });
            }
            return(result.ToArray());
        }
コード例 #2
0
ファイル: ReportController.cs プロジェクト: melisek/Reporting
        public IActionResult GetDiscreteReportDiagram([FromBody] ReportDiagramDiscDto diagram)
        {
            try
            {
                if (diagram == null)
                {
                    throw new BasicException("Invalid input format!");
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var result = _manager.GetDiscreetRiportDiagram(diagram);
                return(Ok(result));
            }
            catch (BasicException ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest(ex.Message));
            }
            catch (NotFoundException ex)
            {
                _logger.LogError(ex.Message);
                return(NotFound(ex.Message));
            }
            catch (PermissionException ex)
            {
                _logger.LogError(ex.Message);
                return(Unauthorized());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest());
            }
        }