예제 #1
0
        public List <СomponetServiceEntity> Read(int minId = DefValInt, int maxId = DefValInt, int minServiceId = DefValInt, int maxServiceId = DefValInt, int minComponetId = DefValInt, int maxComponetId = DefValInt)
        {
            string stringWithWhere = CreateWherePartForReadQuery(minId, maxId, minServiceId, maxServiceId, minComponetId, maxComponetId);

            MySqlCommand command = new MySqlCommand(readString + stringWithWhere);

            command.Connection = connection;

            connection.Open();
            List <СomponetServiceEntity> result = new List <СomponetServiceEntity>();

            try
            {
                MySqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    object idFromDb         = reader["Id"];
                    object ServiceIdFromDb  = reader["ServiceId"];
                    object ComponetIdFromDb = reader["ComponetId"];
                    СomponetServiceEntity componentServes = new СomponetServiceEntity
                    {
                        Id         = System.Convert.ToInt32(idFromDb),
                        ServiceId  = System.Convert.ToInt32(ServiceIdFromDb),
                        ComponetId = System.Convert.ToInt32(ComponetIdFromDb)
                    };
                    result.Add(componentServes);
                }
            }
            finally
            {
                connection.Close();
            }
            return(result);
        }
예제 #2
0
        public void Create(СomponetServiceEntity сomponetServiceEntity)
        {
            connection.Open();
            MySqlCommand   command          = new MySqlCommand(addString);
            MySqlParameter titleParam       = new MySqlParameter("@ComponetId", сomponetServiceEntity.ComponetId);
            MySqlParameter contactInfoParam = new MySqlParameter("@ServiceId", сomponetServiceEntity.ServiceId);

            command.Parameters.Add(titleParam);
            command.Parameters.Add(contactInfoParam);

            command.Connection = connection;

            object obj = null;

            try
            {
                obj = command.ExecuteScalar();
            }
            finally
            {
                connection.Close();
            }
            int id = Convert.ToInt32(obj);

            сomponetServiceEntity.Id = id;
        }
예제 #3
0
        public void Delete(СomponetServiceEntity сomponetServiceEntity)
        {
            connection.Open();
            MySqlCommand   command   = new MySqlCommand(deleteString);
            MySqlParameter parameter = new MySqlParameter("@id", сomponetServiceEntity.Id.ToString());

            command.Parameters.Add(parameter);
            command.Connection = connection;
            try
            {
                int delCount = command.ExecuteNonQuery();
            }
            finally
            {
                connection.Close();
            }
        }
예제 #4
0
        public void Update(СomponetServiceEntity сomponetServiceEntity, int serviceId = DefValInt, int componetId = DefValInt)
        {
            connection.Open();

            string setString = CreateSetPartForUpdateQuery(serviceId, componetId);

            MySqlCommand command = new MySqlCommand(updateString + setString + $" where id = {сomponetServiceEntity.Id};");

            command.Connection = connection;

            try
            {
                int updateCount = command.ExecuteNonQuery();
            }
            finally
            {
                connection.Close();
            }
        }