Exemplo n.º 1
0
        public IEnumerable <RecordAverageDTO> FilterByDate([FromRoute] int userId, double fromDate, double toDate)
        {
            DateHandler dateHandler = new DateHandler();

            string dateFrom = dateHandler.ConvertToSqlStringDate(fromDate);
            string dateTo   = dateHandler.ConvertToSqlStringDate(toDate);


            string _selectString = "SELECT Datepart(\"Day\", \"RecordTime\") as \"DayDate\", Datepart(\"Month\", \"RecordTime\") as \"MonthDate\", avg(\"BPSystolic\") as \"BpSystolicAvg\", avg(\"BPDiastolic\") as \"BpDiastolicAvg\", avg(\"BodyTemperature\") as \"BodyTemperature\", avg(\"HeartBeatPerSecond\") as \"HeartBeatPerSecond\", avg(\"Dust\") as \"Dust\", avg(\"Sulphur\") as \"Sulphur\", avg(\"Nitrogen\") as \"Nitrogen\", avg(\"Fluor\") as \"Fluor\", avg(\"CarbonMonoxide\") as \"CarbonMonoxide\", avg(\"Ozone\") as \"Ozone\", avg(\"RaspberryRecord\".\"Temperature\") as \"Temperature\", avg(\"RaspberryRecord\".\"Pressure\") as \"Pressure\", avg(\"RaspberryRecord\".\"Humudity\") as \"Humidity\" FROM \"Record\" INNER JOIN \"RaspberryRecord\" ON \"Record\".\"UserID\" = \"RaspberryRecord\".\"UserId\" WHERE \"Record\".\"UserID\" = " + userId + " AND \"RecordTime\" BETWEEN " + dateFrom + " AND " + dateTo + " AND \"DateTime\" BETWEEN " + dateFrom + " AND " + dateTo + " group by Datepart (\"Day\", \"RecordTime\"), Datepart (\"Month\", \"RecordTime\")";

            using (var conn = new SqlConnection(connectionString))
            {
                conn.Open();

                using (var cmd = new SqlCommand(_selectString, conn))
                {
                    using (var reader = cmd.ExecuteReader())
                    {
                        List <RecordAverageDTO> RecordList = new List <RecordAverageDTO>();

                        while (reader.Read())
                        {
                            DataReader       dataReader = new DataReader();
                            RecordAverageDTO mtc        = dataReader.ReadRecordAverageDTO(reader);
                            RecordList.Add(mtc);
                        }

                        //ObjectConverter objConverted = new ObjectConverter();
                        //JObject jObject = objConverted.dayJson(RecordList);
                        return(RecordList);
                    }
                }
            }
        }