iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hi,
How do we properly use DataListViewModelBase.SaveDataAsync() method from a modal context? We need to update and save changes to the SelectedItem of a PARENT DataListViewModel, after saving data from a context view (e.g. List A > List B > Editor A > Modal List A > Modal Editor A). When a change has been made to an Item in Modal Editor A, we need to manipulate the SelectedItem on List A and should be saved after the changes on Modal Editor A has been executed (e.g. Modal Editor A.ExecuteSave() followed by List A.SelectedIndex.ExecuteSave()).
We currently implemented this behavior using an event aggregator, which sends a message to List A viewmodel to start manipulating the SelectedItem data and call SaveDataAsync(). See code snippet below, this code doesn't work if the SelectedItem being manipulated is a newly added item. Doesn't work in the sense that the changes are not being saved to the database even though the item clearly changed while it's in the device. Any attempt to save changes to the new item fails; however, once you restart (close > open) the app... any changes being made will be saved to the database.
private async void ExecuteSave(object parameter) { try { // Get the collected date and current date/time. var p_CollectedDate = this.SelectedItem.CollectedDate; var p_CurrentDate = DateTime.Now; if (p_CollectedDate == null) { // Update the collected date if it's null or empty. this.SelectedItem.CollectedDate = p_CurrentDate.Date; this.SelectedItem.TimeIn = p_CurrentDate; } // Always notify the date/time of change. this.SelectedItem.ModifiedOn = DateTime.UtcNow; // Commit changes to entity. this.SelectedItem.EndEdit(); // Update the value to the database. this.Repository.Update(this.SelectedItem); // Raise an item changed event. this.OnDataChanged(this.SelectedItem); // Save the changes to the database. await this.SaveDataAsync(); // Raise an item changed event. this.OnDataChanged(this.SelectedItem); } catch (Exception p_Exception) { Debug.WriteLine(p_Exception.Message); } }
this.Repository.EntityContainer.Attach(yourEntity);
this.Repository.EntityContainer.Attach(yourEntity); ((IAsyncBatchUpdate)this.Repository).EntityContainer.AttachEntity(yourItem, Intersoft.Crosslight.Data.EntityConflictResolution.Replace);
Hi Jimmy,
I would like to confirm several thing about your scenario :
1. you tried have save your item on Modal Editor A, once the save was done (navigation was closed), your current state should be on Editor A. But somehow from your statement, you tried to once again save your item on List A which I take as the view you are on when Modal Editor A was cloased. Could you tell me how you navigate to List A after Modal Editor A was closed? Did you mean you navigate to List A when Modal Editor A.ExecuteSave operation has been completed?
2. Based on your statement :
we need to manipulate the SelectedItem on List A and should be saved after the changes on Modal Editor A has been executed.
The SeletedItem on List A should be the same as the saved item on Modal Editor A (cmiiw). Could you tell me the reason why you need to save the item twice?
3. When Modal Editor A.ExecuteSave was called the editor should show an activity presenter and wait for item successfully saved to databased before it was closed (I assume that your Modal Editor A viewModel was extend from DataEditorViewModelBase). If it was true, when you navigate back to List A, your Modal Editor A should have saved your entity (save was done).
It seem that your scenario was a bit unique. Could you tell me the objective of your scenario? For the time being, I will tried to reproduce this issue on my local end. It will be great help if you could provide me with a sample and a video about how to reproduce this issue.
Best Regards,Leo
Okay, now I get most of it. To tell you the truth, just as you said, the whole A (List A, Modal Editor A, Modal List A) on your description before confused me. Thanks for your description.
To manipulate item on other viewModel, you need to used event aggregator. For your issue with new Item, please let me clarified two thing. Did you add a new Item without saving it to server and only save it after the Item on Modal Editor A has been saved? If so, I recommend you to save the item to server first before you manipulate it again later (when item on Modal Editor A saved). Another option is manual trigger the save on item (example: this.Repository.Insert(this.SelectedItem); ) when the item is a newly added item (have not been saved).
Regards,Leo
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname