1

I have a DNN applicacation and I managed to put a custom module. The module is basically incrementing and decrementing value in a label. And there also have a button named submit which displays only a positive value in the label which is also the value that are being incremented and decremented. The purpose is just for counting the download of a user in an application.

Now here is my decrement code: public void doDecrement(string propertyKey, UserInfo userInformation, int portalID) { int newDownloadCount = GetProfilePropertyValueAsInt(propertyKey, userInformation); ; int result = 0; result = newDownloadCount - 1; userInformation.Profile.SetProfileProperty(propertyKey, result.ToString()); UserController.UpdateUser(portalID, userInformation); }

And here is my increment code:

public void doIncrement(string propertyKey, UserInfo userInformation, int portalID)
{
    int newDownloadCount = GetProfilePropertyValueAsInt(propertyKey, userInformation);
    int result = 0; //initialize to zero
    result = newDownloadCount + 1; //assign new value
                                   //set the profile property to RAM... no need to test because Get will default to zero 
    userInformation.Profile.SetProfileProperty(propertyKey, result.ToString());
    //call update user to write the changes to disk
    UserController.UpdateUser(portalID, userInformation);
}

Here is my submit code so I can update the value:

public void UpdatePropertyValue(string propertyKey, UserInfo userInformation, int portalID, string txtNewVale)
{
    int newDownloadCount = 0;
    int resultValue = 0;
    int.TryParse(txtNewVale, out newDownloadCount);
    if (String.IsNullOrEmpty(txtNewVale))
    {
        newDownloadCount = resultValue;
    }
    userInformation.Profile.SetProfileProperty(propertyKey, newDownloadCount.ToString());
    UserController.UpdateUser(portalID, userInformation);
}

My problem now is,I'm experiencing a road block. I want to save the incremented value in database using postgres. I want that whenever the value is incremented or decremented or updated, it will be save to the database.

I would really appreciate anyone that could help. Thank you in advance.

1 Answer 1

1

As you are probably aware, DNN's data access layer is written for MS SQL Server. There is no official support for open source databases like Postgres or mySQL. However, you can write code that will connect to an external database. It is more difficult but can be done.

Since you already have the increment value being updated in the User Profile (which is stored in the DNN SQL database), you need to write another method that gets the User Profile value and updates an external database.

Start with downloading the .NET Postgres data driver. Add a connection string in the DNN web.config as an app key.

<appSettings>
...
    <add key="PostgresDBConn" value="Server=my-postgres-svr;Port=9090;User Id=dbuser;Password=abc123;Database=dnnExternalTables;" />
...
</appSettings>

Then use the following to retrieve the connection string in your module code:

string connstring = DotNetNuke.Common.Utilities.Config.GetSetting("PostgresDBConn");
NpgsqlConnection conn = new NpgsqlConnection(connstring);
conn.Open();

Then follow an Npgsql example for doing an update like this one.

Sign up to request clarification or add additional context in comments.

1 Comment

The link you've provided is currently broken. Is there a new link to the example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.