public FigureData LoadPolygon(string name)
        {
            var connection = PostgresConnection.GetInstance();

            try
            {
                connection.Open();

                string sql = "select type, x_coords, y_coords from polygons where name=@name";

                var command = new NpgsqlCommand(sql, connection);
                command.Parameters.AddWithValue("@name", name);

                var dataReader = command.ExecuteReader();

                if (!dataReader.Read())
                {
                    throw new DataException("Figure does not exist");
                }

                FigureData figureData = new FigureData();
                figureData.PolygonType = (string)dataReader[0];
                figureData.Coords      = FigureData.GetCoordsFromArrays((double[])dataReader[1], (double[])dataReader[2]);

                return(figureData);
            }
            catch (Exception e)
            {
                throw;
            }
            finally
            {
                connection.Close();
            }
        }
        public void SavePolygon(FigureData polygon, string name)
        {
            var connection = PostgresConnection.GetInstance();

            try
            {
                connection.Open();

                string sql = "insert into polygons (name, type, x_coords, y_coords) " +
                             "values (@name, @type, @x_coords, @y_coords)";

                var command = new NpgsqlCommand(sql, connection);

                command.Parameters.AddWithValue("@name", name);
                command.Parameters.AddWithValue("@type", polygon.PolygonType);

                var dictionary = FigureData.GetArraysFromCoords(polygon.Coords);
                command.Parameters.AddWithValue("@x_coords", dictionary["xCoords"]);
                command.Parameters.AddWithValue("@y_coords", dictionary["yCoords"]);

                command.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                connection.Close();
            }
        }
        public int FiguresCount()
        {
            var connection = PostgresConnection.GetInstance();
            int result     = -1;

            try
            {
                connection.Open();

                var command = new NpgsqlCommand("select polyhedrons_count() + polygons_count()", connection);
                result = (int)command.ExecuteScalar();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                connection.Close();
            }

            return(result);
        }