views:

398

answers:

2

Hi, I'm designing an ASP.NET screen which configures what screens are relevant for a particular type of record. For example a car record will have access to the Ford and Ferrari pages. I'm displaying a listbox on the left with all available items, and a listbox on the right with currently selected items. Two arrow icons allow you to move items from left listbox to right listbox and vice versa.

I'm trying to figure out a good way of storing the selected access. Easiest would be to delete all the currently selected items and reinsert the items from the Selected Items listbox. But the changes need to be audited more accurately so need individual inserts and deletes. Should I store the original items in a hidden field and then try to compare the final selected items with the original? Should the work be done in the Presentation layer, within an object or in a stored procedure?

Thanks for any guidance, Dean

+1  A: 

I would not do it on the presentation layer, send the new list to your business layer. In there retrieve the current list and do a compare with the new list. The do your inserts and deletes based on that.

Robert MacLean
Thanks, so I'm guessing I'd pass a collection into the business layer, then compare that with the actual values. Is there an easy way to do this? Loop around each list and compare with the other to make a list of inserts and deletes?
Dean Madden
If you using LINQ (just LINQ to objects is fine) you can use the intersect method to identify what is new. Anything not in that list is then deleted.
Robert MacLean
Sadly we're still on .NET 2.0
Dean Madden
A: 

If you want the selection to be persistant you should store them in DataLayer.

Business Layer : Car Entity and Cars Collection

At server side you can create a collection of items that contains all (selected/ not selected) items.

A car entity item requires its name, id and selected info. store this collection in session when user enter the page and check it whenever you want.

Here is a Car Item :

CarItem

  • Id
  • Name
  • IsSelected
Canavar