Can somebody give me an example?

Posts   
 
    
Dominique
User
Posts: 22
Joined: 13-Sep-2005
# Posted on: 13-Sep-2005 19:27:32   

Hello,

I'm using Selfservicing. I have a form where a customer can be entered. On the same form, I also have a grid with contact info for that customer. the entity customer and the collection contactinfo have the necessary relations.

What I want to reach is the following:

Scenario 1: The user enters a customer, he also enters multiple contact info records. He clicks save, this should save the customer and the contact info records in a transaction.

Scenario 2: The user enters a customer, he also enters multiple contact info records. He clicks cancel, this should not save the information for customer and contact info records.

Scenario 3: The user enters a customer, he also enters multiple contact info records, but he also deletes some of those contact info records in the grid. The grid should be updated, but not the database until the user clicks the save button. If the user clicks the cancel button, nothing should have changed in the customer or contact records.

It's the third scenario that is giving me a lot of problems. I've tried several options, but I don't seem to get the grid updating without saving the contact info to the database, but that gives me constraint errors when the user is entering a new customer. Also when adding a new contact info record to the grid, how can I resort the grid, so that the new contact info is in the correct location?

Some code I have been trying:

to fill the contactgrid:

IPredicateExpression predicatecontact = new PredicateExpression(); ISortExpression sorter5 = new SortExpression( SortClauseFactory.Create(TravelAgent.Dal.ContactFieldIndex.Contactlabel, SortOperator.Ascending)); fileEntry.SetCollectionParametersContacts(0, sorter5); gridContacts.DataSource = fileEntry.GetMultiContacts(false);

to delete a contact in the grid:

TravelAgent.Dal.EntityClasses.ContactEntity contact = fileEntry.Contacts[BindingContext[fileEntry.Contacts].Position]; IPredicateExpression selectFilter = new PredicateExpression( PredicateFactory.CompareValue(TravelAgent.Dal.ContactinfoFieldIndex.Autonumber, ComparisonOperator.Equal, contact.Autonumber)); fileEntry.Passengers.DeleteMulti(selectFilter);

This does remove the contact, but does not update the grid, also when the cancel button is pressed then, the record is removed anyway.

Can somebody give me a complete example of something like this? _I've been searching for days, but I don't seem to get there. _confused

Thx, Bernaert Dominique. wink

JimFoye avatar
JimFoye
User
Posts: 656
Joined: 22-Jun-2004
# Posted on: 13-Sep-2005 21:57:56   

I believe you should look into the UnitofWork.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 14-Sep-2005 10:00:58   

If you modify or let the user modify an object graph in memory, be aware that if that graph is altered and the alternations have to be rolled back, this often can't be done. LLBLGen Pro entities have a versioning system for field values (SaveFields/RollbackFields) but not for related entities.

If you want to rollback a changed entity graph, it's often more efficient to refetch the entity graph.

Frans Bouma | Lead developer LLBLGen Pro
Dominique
User
Posts: 22
Joined: 13-Sep-2005
# Posted on: 14-Sep-2005 10:55:28   

I tried something simular with the combination of a travelfile and several passengers that are inserted in a grid in the same form.

When I remove a passenger from the grid Using unitofwork I add the passenger record for save to the unit of work with field Passengerremoved = 1 I then manually remove the record from the collection list with removeat I also add the travel file to the unitofwork If the user saves the travel file I execute the unitofwork, so the travelfile is updated and the passenger record is updated. If the users cancels the update, the next time the travel file is opened, the passenger info is back.

Is this a correct way of doing this?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 15-Sep-2005 11:00:00   

Sounds solid to me simple_smile Good example of how to utilize the unitofwork to collect work to be done while the process is in progress simple_smile

Frans Bouma | Lead developer LLBLGen Pro