Exemplo n.º 1
0
        public MetricsData[] Get(int date)
        {
            List <MetricsData> list = new List <MetricsData>();

            using (SqlConnection conn = VenvitoHelper.CreateDbConnection())
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "usp_MetricsData_Get";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("Date", VenvitoHelper.IntToDate(date)));
                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            list.Add(new MetricsData
                            {
                                date        = date,
                                code        = Convert.ToString(dr["MetricsCode"]),
                                description = Convert.ToString(dr["MetricsDescription"]),
                                type        = Convert.ToString(dr["MetricsType"]),
                                color       = Convert.ToString(dr["Color"]),
                                value       = Convert.ToDecimal(dr["MetricsValue"])
                            });
                        }
                    }
                }
            }

            return(list.ToArray <MetricsData>());
        }
Exemplo n.º 2
0
 public void Post([FromBody] MetricsData data)
 {
     using (SqlConnection conn = VenvitoHelper.CreateDbConnection())
     {
         using (SqlCommand cmd = conn.CreateCommand())
         {
             cmd.CommandText = "usp_MetricsData_Update";
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add(new SqlParameter("Date", VenvitoHelper.IntToDate(data.date)));
             cmd.Parameters.Add(new SqlParameter("MetricsCode", data.code));
             cmd.Parameters.Add(new SqlParameter("MetricsValue", data.value));
             cmd.ExecuteNonQuery();
         }
     }
 }
Exemplo n.º 3
0
        public MetricsChart[] Get(string dateRange)
        {
            List <MetricsChart> list = new List <MetricsChart>();

            using (SqlConnection conn = VenvitoHelper.CreateDbConnection())
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "usp_MetricsChart_Get";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@DateRange", dateRange));
                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            list.Add(new MetricsChart
                            {
                                code        = Convert.ToString(dr["MetricsCode"]),
                                description = Convert.ToString(dr["MetricsDescription"]),
                                type        = Convert.ToString(dr["MetricsType"]),
                                color       = Convert.ToString(dr["Color"]),
                                totalValue  = Convert.ToDecimal(dr["MetricsValue"])
                            });
                        }

                        foreach (MetricsChart chart in list)
                        {
                            dr.NextResult();
                            List <MetricsChartData> data = new List <MetricsChartData>();
                            while (dr.Read())
                            {
                                data.Add(new MetricsChartData
                                {
                                    periodName = Convert.ToString(dr["PeriodName"]),
                                    value      = Convert.ToDecimal(dr["MetricsValue"])
                                });
                            }
                            chart.chartData = data.ToArray <MetricsChartData>();
                        }
                    }
                }
            }

            return(list.ToArray <MetricsChart>());
        }