private static void Relink(NoteCollectionModel model)
 {
     foreach (var completedNote in model.CompletedNotes)
     {
         completedNote.NoteCollection = model;
     }
     foreach (var deletedNote in model.DeletedNotes)
     {
         deletedNote.NoteCollection = model;
     }
     foreach (var noteModel in model.NewNotes)
     {
         noteModel.NoteCollection = model;
     }
 }
        private async Task Initialize()
        {
            using (await _isInitializedLock.LockAsync())
            {
                if (_isInitialized)
                    return;

                _isInitialized = true;

                await ExecuteSafe(async () =>
                {
                    if (await RetrieveUserInformationsFromStorage())
                    {
                        await RetrieveNoteCollectionsFromStorage();
                    }
                    else
                    {
                        var coll = new NoteCollectionModel()
                        {
                            Name = "To do",
                            Guid = Guid.NewGuid(),
                            NewNotes = new ObservableCollection<NoteModel>()
                            {
                                new NoteModel()
                                {
                                    Guid = Guid.NewGuid(),
                                    IsCompleted = false,
                                    Content = "Add new Note",
                                    CreateTime = DateTime.Now,
                                    PendingAction = PendingAction.AddOrUpdate
                                },
                                new NoteModel()
                                {
                                    Guid = Guid.NewGuid(),
                                    IsCompleted = false,
                                    Content = "Install Application on my other Windows devices to sync notes",
                                    CreateTime = DateTime.Now,
                                    PendingAction = PendingAction.AddOrUpdate
                                }
                            },
                            CompletedNotes = new ObservableCollection<NoteModel>()
                            {
                                new NoteModel()
                                {
                                    Guid = Guid.NewGuid(),
                                    IsCompleted = true,
                                    Content = "Install to do application",
                                    CreateTime = DateTime.Now,
                                    PendingAction = PendingAction.AddOrUpdate
                                }
                            },
                            PendingAction = PendingAction.AddOrUpdate
                        };
                        NoteCollectionManager.AddNoteCollection(coll);
                    }
                });
            }

            await SyncNotes();
        }
        public Task<bool> Delete(NoteCollectionModel nm)
        {
            return ExecuteSafe(async () =>
            {
                await Initialize();

                var obj = RequestConverter.Instance.ConvertToNoteCollectionRequest(_userInformations.Guid,
                    PossibleActions.Delete,
                    new List<NoteCollectionModel>() { nm });
                var res = await _dataService.PostNoteCollection(obj);
                nm.PendingAction = !res.IsSuccessfull ? PendingAction.Remove : PendingAction.None;

                NoteCollectionManager.RemoveFromCollection(nm);
                if (nm.PendingAction != PendingAction.None)
                    NoteCollectionManager.AddDeletedNoteCollection(nm);

                return await SaveNoteCollectionsToStorage() && res.IsSuccessfull;
            });
        }
        private void SelectNote(NoteModel note)
        {
            _navigationService.NavigateTo(PageKeys.NotePage.ToString());
            SimpleIoc.Default.GetInstance<NoteViewModel>().SelectNote(note);

            _activeCollection = note.NoteCollection;
            RaisePropertyChanged(() => ActiveCollection);
        }
 private async void SaveNoteCollection(NoteCollectionModel model)
 {
     using (_saveNoteCollection.GetProgressDisposable(_progressService, ProgressKeys.SavingNote))
     {
         await _noteRepository.Save(model);
     }
 }
 public bool CanSaveNoteCollection(NoteCollectionModel model)
 {
     return !string.IsNullOrEmpty(model?.Name);
 }
 private async void RemoveNoteCollection(NoteCollectionModel model)
 {
     using (_removeNoteCollection.GetProgressDisposable(_progressService, ProgressKeys.SavingNote))
     {
         if (model == ActiveCollection)
         {
             var index = NoteCollections.IndexOf(ActiveCollection);
             if (index == 0)
                 ActiveCollection = NoteCollections[1];
             else
                 ActiveCollection = NoteCollections[--index];
         }
         await _noteRepository.Delete(model);
         Messenger.Default.Send(Messages.NotesChanged);
     }
 }
 public bool CanRemoveNoteCollection(NoteCollectionModel model)
 {
     return NoteCollections.Count > 1;
 }
        private async void AddNoteCollection()
        {
            using (_addNoteCollectionCommand.GetProgressDisposable(_progressService, ProgressKeys.SavingNote))
            {
                var newNoteCollection = new NoteCollectionModel()
                {
                    Guid = Guid.NewGuid(),
                    Name = NewNoteCollection,
                    CreateTime = DateTime.Now
                };
                await _noteRepository.Save(newNoteCollection);
                NewNoteCollection = "";

                ActiveCollection = newNoteCollection;
            }
        }
 public static void RemoveFromDeletedCollection(NoteCollectionModel model)
 {
     if (DeletedCollections.Contains(model))
         DeletedCollections.Remove(model);
 }
 public static void RemoveFromCollection(NoteCollectionModel model)
 {
     if (Collections.Contains(model))
         Collections.Remove(model);
 }
 public static void AddDeletedNoteCollection(NoteCollectionModel model)
 {
     Relink(model);
     DeletedCollections.Add(model);
 }
 public static void TryAddNoteCollection(NoteCollectionModel model)
 {
     if (!Collections.Contains(model))
         AddNoteCollection(model);
 }
 public async Task<bool> Delete(NoteCollectionModel nm)
 {
     return true;
 }