public int Put(int id, [FromBody] EnvironmentClass value)
        {
            const string updateString =
                "update EnvironmentData set oxygen =@oxygen, co2 =@co2, co =@co, [PM2.5] =@pm25, PM10 =@pm10, ozon =@ozon, dustParticles =@dustParticles, nitrogenDioxide =@nitrogenDioxide, sulphurDioxide =@SulphurDioxide, longitude=@longitude, latitude=@latitude, userId =@userId, dateTimeInfo =@dateTimeInfo where id=@id;";

            using (SqlConnection databaseConnection = new SqlConnection(connectionString))
            {
                databaseConnection.Open();
                using (SqlCommand updateCommand = new SqlCommand(updateString, databaseConnection))
                {
                    updateCommand.Parameters.AddWithValue("@id", id);
                    updateCommand.Parameters.AddWithValue("@oxygen", value.Oxygen);
                    updateCommand.Parameters.AddWithValue("@co2", value.Co2);
                    updateCommand.Parameters.AddWithValue("@co", value.Co);
                    updateCommand.Parameters.AddWithValue("@pm25", value.Pm25);
                    updateCommand.Parameters.AddWithValue("@pm10", value.Pm10);
                    updateCommand.Parameters.AddWithValue("@ozon", value.Ozon);
                    updateCommand.Parameters.AddWithValue("@dustParticles", value.DustParticles);
                    updateCommand.Parameters.AddWithValue("@nitrogenDioxide", value.NitrogenDioxide);
                    updateCommand.Parameters.AddWithValue("@sulphurDioxide", value.SulphurDioxide);
                    updateCommand.Parameters.AddWithValue("@longitude", value.Longitude);
                    updateCommand.Parameters.AddWithValue("@latitude", value.Latitude);
                    updateCommand.Parameters.AddWithValue("@userId", value.UserId);
                    updateCommand.Parameters.AddWithValue("@dateTimeInfo", value.DateTimeInfo);

                    int rowsAffected = updateCommand.ExecuteNonQuery();
                    return(rowsAffected);
                }
            }
        }
        public int Post([FromBody] EnvironmentClass value)
        {
            string insertString =
                "insert into EnvironmentData (oxygen, co2, co, [PM2.5], PM10, ozon, dustParticles, nitrogenDioxide, sulphurDioxide, longitude, latitude, userId, dateTimeInfo) values(@oxygen, @co2, @co, @PM25, @PM10, @ozon, @dustParticles, @nitrogenDioxide, @sulphurDioxide, @longitude, @latitude, @userId, @dateTimeInfo)";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                using (SqlCommand command = new SqlCommand(insertString, conn))
                {
                    command.Parameters.AddWithValue("@oxygen", value.Oxygen);
                    command.Parameters.AddWithValue("@co2", value.Co2);
                    command.Parameters.AddWithValue("@co", value.Co);
                    command.Parameters.AddWithValue("@PM25", value.Pm25);
                    command.Parameters.AddWithValue("@PM10", value.Pm10);
                    command.Parameters.AddWithValue("@ozon", value.Ozon);
                    command.Parameters.AddWithValue("@dustParticles", value.DustParticles);
                    command.Parameters.AddWithValue("@nitrogenDioxide", value.NitrogenDioxide);
                    command.Parameters.AddWithValue("@sulphurDioxide", value.SulphurDioxide);
                    command.Parameters.AddWithValue("@longitude", value.Longitude);
                    command.Parameters.AddWithValue("@latitude", value.Latitude);
                    command.Parameters.AddWithValue("@userId", value.UserId);
                    command.Parameters.AddWithValue("@dateTimeInfo", value.DateTimeInfo);

                    int rowsAffected = command.ExecuteNonQuery();
                    return(rowsAffected);
                }
            }
        }
Example #3
0
        public void TestPostEnvironment()
        {
            DateTime         tryDate = new DateTime(2018, 01, 01);
            EnvironmentClass newEnv  = new EnvironmentClass
            {
                Oxygen          = 7,
                Co2             = 7,
                Co              = 19,
                Pm25            = 18,
                Pm10            = 45,
                Ozon            = 22,
                DustParticles   = 11,
                NitrogenDioxide = 12,
                SulphurDioxide  = 34,
                Longitude       = 67,
                Latitude        = 8,
                UserId          = 2,
                DateTimeInfo    = tryDate
            };
            int EnvCount = _controller.Post(newEnv);

            Assert.AreEqual(1, EnvCount);

            IEnumerable <EnvironmentClass> envList = _controller.Get();

            Assert.AreEqual(4, envList.Count()); // Passed
        }
Example #4
0
 public void InitializeSession(Session session)
 {
     this.session = session;
     Console      = new ConsoleClass(session);
     Environment  = new EnvironmentClass(session);
     Path         = new PathClass(session);
     File         = new FileClass(session);
     Directory    = new DirectoryClass(session);
     Thread       = new ThreadClass(session);
     Process      = new ProcessClass(session);
 }
        public IEnumerable <EnvironmentClass> Get()
        {
            string selectString = "select * from EnvironmentData;";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                using (SqlCommand command = new SqlCommand(selectString, conn))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        List <EnvironmentClass> result = new List <EnvironmentClass>();
                        while (reader.Read())
                        {
                            EnvironmentClass env = ReadEnvironment(reader);
                            result.Add(env);
                        }
                        return(result);
                    }
                }
            }
        }
        public IEnumerable <EnvironmentClass> GetEnvByUserId(int userId)
        {
            const string selectString = "select * from EnvironmentData where userid =@userid";

            using (SqlConnection databaseConnection = new SqlConnection(connectionString))
            {
                databaseConnection.Open();
                using (SqlCommand selectCommand = new SqlCommand(selectString, databaseConnection))
                {
                    selectCommand.Parameters.AddWithValue("@userid", userId);
                    using (SqlDataReader reader = selectCommand.ExecuteReader())
                    {
                        List <EnvironmentClass> envList = new List <EnvironmentClass>();
                        while (reader.Read())
                        {
                            EnvironmentClass env = EnvironmentController.ReadEnvironment(reader);
                            envList.Add(env);
                        }
                        return(envList);
                    }
                }
            }
        }
Example #7
0
        public void TestPutEnvironment()
        {
            DateTime         tryDate = new DateTime(2019, 02, 02);
            EnvironmentClass newEnv  = new EnvironmentClass
            {
                Oxygen          = 18,
                Co2             = 7,
                Co              = 19,
                Pm25            = 18,
                Pm10            = 45,
                Ozon            = 22,
                DustParticles   = 11,
                NitrogenDioxide = 12,
                SulphurDioxide  = 34,
                Longitude       = 67,
                Latitude        = 8,
                UserId          = 2,
                DateTimeInfo    = tryDate
            };
            int EnvCount = _controller.Put(7, newEnv);

            Assert.AreEqual(18, newEnv.Oxygen); // Passed
        }
        internal static EnvironmentClass ReadEnvironment(SqlDataReader reader)
        {
            int      id              = reader.GetInt32(0);
            decimal  oxygen          = reader.IsDBNull(1) ? 0 : reader.GetDecimal(1);
            decimal  co2             = reader.IsDBNull(2) ? 0 : reader.GetDecimal(2);
            decimal  co              = reader.IsDBNull(3) ? 0 : reader.GetDecimal(3);
            decimal  pm25            = reader.IsDBNull(4) ? 0 : reader.GetDecimal(4);
            decimal  pm10            = reader.IsDBNull(5) ? 0 : reader.GetDecimal(5);
            decimal  ozon            = reader.IsDBNull(6) ? 0 : reader.GetDecimal(6);
            decimal  dustParticles   = reader.IsDBNull(7) ? 0 : reader.GetDecimal(7);
            decimal  nitrogenDioxide = reader.IsDBNull(8) ? 0 : reader.GetDecimal(8);
            decimal  sulphurDioxide  = reader.IsDBNull(9) ? 0 : reader.GetDecimal(9);
            decimal  longitude       = reader.GetDecimal(10);
            decimal  latitude        = reader.GetDecimal(11);
            int      userId          = reader.GetInt32(12);
            DateTime dateTimeInfo    = reader.GetDateTime(13);

            EnvironmentClass env = new EnvironmentClass()
            {
                Id              = id,
                Oxygen          = oxygen,
                Co2             = co2,
                Co              = co,
                Pm25            = pm25,
                Pm10            = pm10,
                Ozon            = ozon,
                DustParticles   = dustParticles,
                NitrogenDioxide = nitrogenDioxide,
                SulphurDioxide  = sulphurDioxide,
                Longitude       = longitude,
                Latitude        = latitude,
                UserId          = userId,
                DateTimeInfo    = dateTimeInfo
            };

            return(env);
        }