﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - Crosslight - How to Use Crosslight to Properly Save a SelectedItem in a DataListViewModelBase?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-to-Properly-Save-a-SelectedItem-in-a-DataListViewModelBase/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>How to Use Crosslight to Properly Save a SelectedItem in a DataListViewModelBase?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-to-Properly-Save-a-SelectedItem-in-a-DataListViewModelBase/</link><pubDate>Wed, 23 Sep 2015 08:28:34 GMT</pubDate><dc:creator>nicholaslie</dc:creator><description>&lt;div&gt;You'll simply need this code:&lt;/div&gt;&lt;div&gt;&lt;pre&gt;this.Repository.EntityContainer.Attach(yourEntity);&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;And here's the documentation on that:&amp;nbsp;&lt;a href="http://developer.intersoftsolutions.com/display/crosslight/Tracking+and+Saving+Changes" target="_blank" style="font-size: 10pt;"&gt;http://developer.intersoftsolutions.com/display/crosslight/Tracking+and+Saving+Changes&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;If you update entities out of our usual lifecycle, you'll still need to insert your entity to the EntityContainer, since the EntityContainer manages the relationships between the entities, and it also tracks the EntityState, whether it's newly added, modified, or deleted.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Much like in our implementation in AppFramework, (&lt;a href="http://git.intersoftsolutions.com/projects/CROS/repos/frameworks/browse/Intersoft.AppFramework/ModelServices/EditableEntityRepository.cs" target="_blank"&gt;http://git.intersoftsolutions.com/projects/CROS/repos/frameworks/browse/Intersoft.AppFramework/ModelServices/EditableEntityRepository.cs&lt;/a&gt;, line 181), this is what truly happens when you perform SaveChangesAsync(), it executes PrepareSavedEntities, which relies on the information from the EntityContainer.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;So what you have done is correct, but to be able to edit the item, the entity needs to be inserted to the EntityContainer first.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;If the code doesn't work, it might need the additional Replace param as the EntityConflictResolution strategy.&lt;/div&gt;&lt;div&gt;&lt;pre&gt;this.Repository.EntityContainer.Attach(yourEntity); ((IAsyncBatchUpdate)this.Repository).EntityContainer.AttachEntity(yourItem, Intersoft.Crosslight.Data.EntityConflictResolution.Replace);&lt;/pre&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;</description></item><item><title>How to Use Crosslight to Properly Save a SelectedItem in a DataListViewModelBase?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-to-Properly-Save-a-SelectedItem-in-a-DataListViewModelBase/</link><pubDate>Wed, 23 Sep 2015 04:13:25 GMT</pubDate><dc:creator>jtungol@silentpartnersoft.com</dc:creator><description>Okay, our goal is to add an item to the DataListViewModelBase&amp;lt;TModel, TRepository&amp;gt;() without using the built-in funtionality due to complex reasons. One reason being is that the items are being added by executing a stored procedure from the server side. Now... how do we properly add an item to the list when the item created is already at hand (meaning any process of creating the new item is done)? I did say properly, because using this.SourceItems.Add(newitemfromserver) does add the item to the list visually, but any attempt to modify the new item is not working. No matter how many times you call the ExecuteSave method mentioned above in an earlier post doesn't seem to be working because the newitem seems to be locked or something. The newitem can be modified from the client side, but somehow it is not being tracked as changed; thus, any changes from the client side is being ignored by the Web API and is not saving the changes to the database. We even tried to invoke the BeginEdit() method for the new item before making any modifications but still nothing.&lt;br&gt;&lt;br&gt;But, here's the thing... when you refresh the list from the client side and then modify the new item and save the changes. Yeah, guess what... it works. But that is going to consume some bandwidth when there's only one item that is added and you need to refresh the whole list just to make it work. By that I mean calling either this.ExecuteRefresh(), this.RefreshData, or this.LoadData after inserting one item. That's just weird, but there must be something missing from our code. Furthermore, we also included/attached the data for the navigation properties on the new item to match the existing items, but that doesn;t make any sense. Is there something else that we need to do once we call the this.SourceItems.Add(newitemfromserver) method?&lt;br&gt;</description></item><item><title>How to Use Crosslight to Properly Save a SelectedItem in a DataListViewModelBase?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-to-Properly-Save-a-SelectedItem-in-a-DataListViewModelBase/</link><pubDate>Mon, 14 Sep 2015 10:36:08 GMT</pubDate><dc:creator>leo.c</dc:creator><description>&lt;p&gt;Hi Jimmy,&lt;/p&gt;&lt;p&gt;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.&lt;/p&gt;&lt;p&gt;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&lt;i&gt; (example:&amp;nbsp;this.Repository.Insert(this.SelectedItem); )&amp;nbsp;&lt;/i&gt;when the item is a newly added item (have not been saved).&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Regards,&lt;br&gt;Leo&lt;/p&gt;</description></item><item><title>How to Use Crosslight to Properly Save a SelectedItem in a DataListViewModelBase?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-to-Properly-Save-a-SelectedItem-in-a-DataListViewModelBase/</link><pubDate>Fri, 11 Sep 2015 14:41:57 GMT</pubDate><dc:creator>jtungol@silentpartnersoft.com</dc:creator><description>Do you realize I didn't mention anything about navigating to &lt;span style="font-weight: bold;"&gt;List A&lt;/span&gt;? When the app loads, List A would be the first view that you'll see. It's probably unique, all software are unique... I understand you are merely confused. The objective has already been mentioned... remember, we need to update the SelectedItem from &lt;span style="font-weight: bold;"&gt;List A&lt;/span&gt; (NOT &lt;span style="font-weight: bold;"&gt;Modal List A&lt;/span&gt;) when something is being updated/saved from &lt;span style="font-weight: bold;"&gt;Modal Editor A&lt;/span&gt;? That's the objective. Which means the &lt;span style="font-weight: bold;"&gt;SelectedItem&lt;/span&gt; from &lt;span style="font-weight: bold;"&gt;List A&lt;/span&gt; will be manipulated or updated after saving an item from &lt;span style="font-weight: bold;"&gt;Modal Editor A&lt;/span&gt;. We don't care anything about an activity presenter.&amp;nbsp; I don't know why it isn't clear... the scenario is straight forward, I don't understand why you are confused by the navigation while there isn't any navigation happening. While it is true that the FormView will close when you save an item from &lt;span style="font-weight: bold;"&gt;Modal Editor A&lt;/span&gt;, we configured the modal navigation context (&lt;span style="font-weight: bold;"&gt;Modal List A&lt;/span&gt; and &lt;span style="font-weight: bold;"&gt;Modal Editor A&lt;/span&gt;) to stay modal. &lt;br&gt;&lt;br&gt;Read the first post again and try to understand the navigation from &lt;span style="font-weight: bold;"&gt;List A&lt;/span&gt; to &lt;span style="font-weight: bold;"&gt;Modal Editor A&lt;/span&gt;. Why would I save the same item twice? I don't believe we mentioned anything about an item being saved twice. FYI, the &lt;span style="font-weight: bold;"&gt;SelectedItem&lt;/span&gt; mentioned is from &lt;span style="font-weight: bold;"&gt;List A&lt;/span&gt; and NOT from &lt;span style="font-weight: bold;"&gt;Modal List A&lt;/span&gt;... so there's no saving the same item twice. Now, you can't go way back to &lt;span style="font-weight: bold;"&gt;List A&lt;/span&gt; after saving an item from &lt;span style="font-weight: bold;"&gt;Modal Editor A&lt;/span&gt; 'cause that's way too many backward navigation. Even when the modal context has closed, the current view should still be &lt;span style="font-weight: bold;"&gt;Editor A&lt;/span&gt;. So, the only way we thought of reaching the viewmodel for &lt;span style="font-weight: bold;"&gt;List A&lt;/span&gt; is by using an event aggregator and execute the code snippet above. That means after saving an Item from &lt;span style="font-weight: bold;"&gt;Modal Editor A&lt;/span&gt; we published an event to notify the viewmodel for &lt;span style="font-weight: bold;"&gt;List A&lt;/span&gt; and start the ExecuteSave() method above. Now, assuming that it is clear enough... is there a better way of doing this?&lt;br&gt;</description></item><item><title>How to Use Crosslight to Properly Save a SelectedItem in a DataListViewModelBase?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-to-Properly-Save-a-SelectedItem-in-a-DataListViewModelBase/</link><pubDate>Fri, 11 Sep 2015 10:34:17 GMT</pubDate><dc:creator>leo.c</dc:creator><description>&lt;p&gt;Hi Jimmy,&lt;/p&gt;&lt;p&gt;I would like to confirm several thing about your scenario :&lt;/p&gt;&lt;p&gt;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?&lt;/p&gt;&lt;p&gt;2. Based on your statement :&amp;nbsp;&lt;/p&gt;&lt;blockquote style="padding-left: 10px; margin: 0px 0px 0px 5px; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"&gt;&lt;i&gt;we need to manipulate the SelectedItem on List A and should be saved after the changes on Modal Editor A has been executed.&lt;/i&gt;&lt;/blockquote&gt;&lt;p&gt;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?&lt;/p&gt;&lt;p&gt;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).&lt;/p&gt;&lt;p&gt;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.&lt;/p&gt;&lt;p&gt;Best Regards,&lt;br&gt;Leo&lt;/p&gt;</description></item><item><title>How to Use Crosslight to Properly Save a SelectedItem in a DataListViewModelBase?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-to-Properly-Save-a-SelectedItem-in-a-DataListViewModelBase/</link><pubDate>Wed, 09 Sep 2015 16:48:43 GMT</pubDate><dc:creator>jtungol@silentpartnersoft.com</dc:creator><description>Anything?&lt;br&gt;</description></item><item><title>How to Use Crosslight to Properly Save a SelectedItem in a DataListViewModelBase?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-to-Properly-Save-a-SelectedItem-in-a-DataListViewModelBase/</link><pubDate>Tue, 08 Sep 2015 21:18:23 GMT</pubDate><dc:creator>jtungol@silentpartnersoft.com</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;&lt;p&gt;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 &amp;gt; List B &amp;gt; Editor A &amp;gt; Modal List A &amp;gt; 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()).&lt;/p&gt;&lt;p&gt;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 &amp;gt; open) the app... any changes being made will be saved to the database.&lt;/p&gt;&lt;pre&gt;        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);
            }
        }&lt;/pre&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>