예제 #1
0
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Notes.Clear();
                var notes = await PluralsightDataStore.GetNotesAsync();

                foreach (var note in notes)
                {
                    Notes.Add(note);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
예제 #2
0
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Notes.Clear();
                // this gets complicated
                // PluralSightDataStore is a (member ...property? )
                // created in BaseViewModel via DependencyService
                // it is of type IPluralSightDataStore
                var notes = await PluralsightDataStore.GetNotesAsync();

                foreach (var note in notes)
                {
                    Notes.Add(note);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
예제 #3
0
        public ItemsViewModel()
        {
            Title            = "Browse";
            Notes            = new ObservableCollection <Note>();
            LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand());

            // Handle "SaveNote" message
            MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "SaveNote",
                                                             async(sender, note) => {
                // Add note to collection - will automatically refresh data binding
                Notes.Add(note);
                // Add to data store
                await PluralsightDataStore.AddNoteAsync(note);
            });

            // Handle "UpdateNote" message
            MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "UpdateNote",
                                                             async(sender, note) => {
                // Update note in data store
                await PluralsightDataStore.UpdateNoteAsync(note);
                // Modifying a member (our note) within an ObservableCollection
                //  does not automatically refresh data binding .. so explicitly
                //  repopulate the collection
                await ExecuteLoadItemsCommand();
            });

            /*
             * MessagingCenter.Subscribe<NewItemPage, Item>(this, "AddItem", async (obj, item) =>
             * {
             *  var newItem = item as Item;
             *  Items.Add(newItem);
             *  await DataStore.AddItemAsync(newItem);
             * });
             */
        }
        public ItemsViewModel()
        {
            Title            = "Browse";
            Notes            = new ObservableCollection <Note>();
            LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand());

            MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "SaveNote",
                                                             async(sender, note) => {
                Notes.Add(note);
                await PluralsightDataStore.AddNoteAsync(note);
            });
        }
예제 #5
0
        public ItemsViewModel()
        {
            Title            = "Browse";
            Notes            = new ObservableCollection <Note>();
            LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand());

            //step 7 subscribe to message
            // he throws in an lambda with two outs in the bottome of the 9th
            MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "SaveNote",
                                                             async(sender, note) => {
                Notes.Add(note);
                await PluralsightDataStore.AddNoteAsync(note);
            });
        }
예제 #6
0
        public ItemsViewModel()
        {
            Title            = "Browse";
            Notes            = new ObservableCollection <Note>();
            LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand());

            MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "SaveNote", async(sender, note) =>
            {
                var newNote = note as Note;
                Notes.Add(newNote);
                await PluralsightDataStore.AddNoteAsync(newNote);
            });

            MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "UpdateNote",
                                                             async(sender, note) => {
                // Update note in data store
                await PluralsightDataStore.UpdateNoteAsync(note);
                // Modifying a member (our note) within an ObservableCollection
                //  does not automatically refresh data binding .. so explicitly
                //  repopulate the collection
                await ExecuteLoadItemsCommand();
            });
        }
예제 #7
0
 async void InitializedCourseList()
 {
     CourseList = await PluralsightDataStore.GetCoursesAsync();
 }
예제 #8
0
        async void InitializeCourselist()
        {
            CourseList = await PluralsightDataStore.GetCoursesAsync();

            MealList = await PluralsightDataStore.GetMealingsAsync();
        }