Пример #1
0
        public List <long> GetIds(int i) //получает лист id(в cards) по выборке
        {
            List <long> list        = new List <long>();
            string      specialName = new ManagmentController().GetSpecialNameUsingType(Type);

            using (NpgsqlConnection connection = new NpgsqlConnection(Connection.ConnectionString))
            {
                connection.Open();
                var cmd    = new NpgsqlCommand($"select id from {specialName} where \"{GetProperty(i)}\" = '{GetValue(i)}' ", connection);
                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    list.Add(reader.GetInt64(0));
                }
            }

            return(list);
        }
Пример #2
0
        private CardsModels GetOutputForCard(long id)
        {
            var card = new CardsModels();

            using (var connection = new NpgsqlConnection(ConnectionString))
            {
                connection.Open();
                using (var command = new NpgsqlCommand($"SELECT * FROM public.cards where id={id};", connection))
                {
                    var reader = command.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            card.Id          = reader.GetInt64(0);
                            card.Name        = reader.GetString(1);
                            card.Type        = reader.GetString(2);
                            card.Image       = reader.GetString(4);
                            card.Information = reader.GetString(5);
                            card.Cost        = reader.GetInt32(6);
                        }
                    }
                }
            }

            string specialName = new ManagmentController().GetSpecialNameUsingType(card.Type); //интересно что будет

            using (NpgsqlConnection connection = new NpgsqlConnection(ConnectionString))
            {
                string[] namesOfProperties = null;
                var      properties        = new List <string>();
                int      numOfColumns      = 0;

                connection.OpenAsync();
                NpgsqlCommand cmd    = new NpgsqlCommand($"SELECT count(*) FROM information_schema.columns where table_name='{specialName}'", connection);
                var           reader = cmd.ExecuteReaderAsync();
                while (reader.Result.Read())
                {
                    numOfColumns = reader.Result.GetInt32(0);
                }
                connection.Close();

                connection.OpenAsync();
                cmd    = new NpgsqlCommand($"select * from {specialName} where id={id}", connection);
                reader = cmd.ExecuteReaderAsync();
                while (reader.Result.Read())
                {
                    for (int i = 1; i < numOfColumns; i++)
                    {
                        properties.Add(reader.Result.GetString(i));
                    }
                }
                connection.Close();
                connection.OpenAsync();
                cmd    = new NpgsqlCommand($"select properties from types where type='{card.Type}'", connection);
                reader = cmd.ExecuteReaderAsync();
                while (reader.Result.Read())
                {
                    namesOfProperties = (string[])reader.Result.GetValue(0);
                }
                connection.Close();
                ViewBag.NamesOfProperties = namesOfProperties;
                ViewBag.Properties        = properties;
            }
            return(card);
        }