Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Pass UserID as parameter to Delete method of ObjectDataSourcePass UserID as parameter to Delete method of ObjectDataSource
Previous
 
Next
New Post
7/3/2009 2:22 PM
 

 Hi!

I'm not sure if this question has been asked before, my search in the forums did not return anything useful.

I have a couple of modules that provide basic insert, update and delete functionality and they work 100%.  In the interim, an additional requirement for auditing was added for the site and after doing some research I decided to use triggers in the SQL database.

This was fairly easy to implement for the inserts and updates seeing as I'm able to easily pass the userid to the stored procedures in the ObjectDataSource_Inserting/Updating methods using the following line of code:


e.InputParameters("UserId") = UserId.ToString

However, when it came to doing the same for the delete method, I ran into some trouble. I have changed the delete stored procedure and all the methods in the various layers to accept UserID as an additional parameter, but when I insert the line of code above into the ObjectDataSource_Deleting method, I get the following error:


"The OrderedDictionary is readonly and cannot be modified."

I Googled the error and most of the "solutions" indicate that you have to add your column to the DataKeyNames property of the Gridview.  I'm not expert in web development, this is why I chose DNN. But I'm not sure that I agree with this solution seeing as UserID is not part of the primary key in my table.

I would appreciate it if somebody can assist me in this regard or at least point me in the right direction.

Regards,
Michelle

 
New Post
7/3/2009 4:34 PM
 

I think it is understandable why the delete parameters cannot be modified. The information is being deleted :)

We have implemented the auditing you describe and what we did was make a "onDelete" trigger that looked for the UserID in the table (this was written when the record was inserted or updated) and inserted it's value into the "Audit table".

Now you probably want to grab the UserID of the person who did the "deleting". No problem. Update the UserID in the record with their UserID right before you do the delete :)



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
7/8/2009 3:08 AM
 

Hi Michael

Thanks for your reply.  Your thought trail is one that I followed exactly.  I suppose I should give you more information to explain exactly where I'm getting stuck.

Seeing as the information is being deleted, I added an update statement to my "delete" stored procedure in the database.  Herewith the example code:

ALTER procedure xxxx

 @ModuleId Int,
 @DetailItemId int,
 @UserId int
 
as

--This is a work around for the auditing purposes
--We need to know who the user is that deleted this record.  But because the user is not SQL managed and rather
--managed in the Users table and by the DotNetNuke application, we have to provide the trigger with the user that
--actually deleted the record and therefore it is passed into this procedure as a parameter.

--We have to be careful now, because we need to update the ByUser, field for the trigger to use, but not log an "Update" in the audit table

--If you'll look carefully at the trigger,
--you'll see that we don't log an audit if just the "ByUser" column is updated

BEGIN
 UPDATE Table
 SET CreatedByUser = @UserId
 WHERE ItemId = @DetailItemId
END

BEGIN
 --Now that the user is updated to the person who is deleting the record, we will pick it up in the trigger and log it as such
 DELETE
 FROM Table
 WHERE ItemId = @DetailItemId
END

Where I get stuck, is that in order for me to update the UserID, it has to be passed into the stored procedure from the front end.  I am using the normal "delete" method of the object data source, which does not call any "update" related methods or procedures from the front end or in the other layers because that is how it is set up. 

So in essence, what I actually need, is to know who the person is on the front end that hit the "delete" button.  I only care about who that person is on the front end.  As soon as the delete proc is hit in the database, I run the update statement, then immediately after that the delete, and the trigger code is clever enough to log the user that deleted the information into the audit table.

Based on your suggestion, is there a way that I can call an "update" method from the front end when the object data source is asked to execute the procedure in the delete method?  The only way I can imagine doing this is with code on the front end, but I'm not sure where to start...

Am I making sense?

:-)

 
New Post
7/8/2009 5:48 PM
 

Michelle Mc Cabe wrote
 

Where I get stuck, is that in order for me to update the UserID, it has to be passed into the stored procedure from the front end.  I am using the normal "delete" method of the object data source, which does not call any "update" related methods or procedures from the front end or in the other layers because that is how it is set up. 

Yeah you would think that (this woud be a logical way of thinking), but actually you:

1) Have a field on the table that stores "LastUserID"

2) Before you delete the record you update that field

3) Then you delete (wrap 2 & 3 in a single Transaction)

4) In your delete trigger you grab the UserID you set on #1

Michelle Mc Cabe wrote

Based on your suggestion, is there a way that I can call an "update" method from the front end when the object data source is asked to execute the procedure in the delete method?  The only way I can imagine doing this is with code on the front end, but I'm not sure where to start...

Yes there is, you can wire up an event to the "deleting" event of the Object Data Source and just handle the update and delete yourself :)



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
7/9/2009 11:59 AM
 

Hi Michael

Thank you for your reply and effort in assisting me, I greatly appreciate it.

I'm going to do what you suggest.  I hope that I understand how, seeing as I'm not a very clued up web developer.  I'm very much interested in your comment about wrapping 2 & 3 in a single transaction.

I would like to follow best practice.  I am not interested that you provide me with the code, merely that I understand the solution and do it well.

So would I be doing it correctly by calling the "update" method in vb of the same data source, force the input parameter for userid to be the current logged on user, and as soon as that is done, then the delete method will continue it's work, in which case the trigger will execute and I have my solution.

I'm going to implement what I have said in the above paragraph hoping that it is what I need. Should I be concerned about the fact that I'm making two trips to the host server on every delete? (i.e. calling update and then delete?)  I hope that doesn't interfere.

Thanks again!

Michelle

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Pass UserID as parameter to Delete method of ObjectDataSourcePass UserID as parameter to Delete method of ObjectDataSource


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out