Print Page | Close Window

Added Item Not Visible after save

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4011
Printed Date: 20-Apr-2024 at 10:57am


Topic: Added Item Not Visible after save
Posted By: gregweb
Subject: Added Item Not Visible after save
Date Posted: 27-Feb-2013 at 6:29pm
This works fine in TempHire, but in my Cocktail project, after a phone number is added, and the save button is invoked, the Phone disappears from the list.

If I put it back into edit mode, it appears again. Or if the refresh button is clicked, it appears.

The item is being saved to the db properly as it shows up fine after the refresh.

I am not seeing what the issue is.

Greg



Replies:
Posted By: gregweb
Date Posted: 27-Feb-2013 at 6:50pm
Found the issue: I had not implemented IHasRoot on the PhoneNumber entity so the SyncInterceptor was not syncing it.

Greg


Posted By: mgood
Date Posted: 27-Feb-2013 at 6:59pm
W/o seeing your code it's gonna be impossible for me to tell. In TempHire the phone numbers are kept in a BindableCollection of StaffingResourcePhoneItemViewModels. During VM initialization, the collection is populated from the phone number navigation property and then the VM listens to the CollectionChanged event of the navigation property to keep the BindableCollection in sync with the navigation property. If you follow the same model, then perhaps you got a bug in the CollectionChanged event handler. Also make sure that you unhook properly from the CollectionChanged event, so you don't have memory leaks and don't react to events from previous entities. The following is the code from TempHire, that keeps the collection in sync.

        private void PhoneNumbersCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.OldItems != null)
            {
                foreach (var item in
                    e.OldItems.Cast<PhoneNumber>().Select(p => PhoneNumbers.First(i => i.Item == p)))
                {
                    PhoneNumbers.Remove(item);
                    item.Dispose();
                }
            }

            if (e.NewItems != null)
                e.NewItems.Cast<PhoneNumber>()
                    .ForEach(p => PhoneNumbers.Add(new StaffingResourcePhoneItemViewModel(p, EditMode)));

            EnsureDelete();
        }


Posted By: mgood
Date Posted: 27-Feb-2013 at 7:00pm
Originally posted by gregweb

Found the issue: I had not implemented IHasRoot on the PhoneNumber entity so the SyncInterceptor was not syncing it.

Greg

I see. Looks like our posts crossed paths. 


Posted By: gregweb
Date Posted: 28-Feb-2013 at 8:44am
Thanks Marcel.



Print Page | Close Window