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>()); }
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(); } } }
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>()); }