private async void RemoveEntry(ViewModel_DiaryEntry entry) { //Removes an entry bool answer = await App.Current.MainPage.DisplayAlert("Removing a Diary Entry", "Are you sure you want to delete this Diary Entry?", "Yes", "No"); if (answer == true) { Console.WriteLine("Removing Entry "); DiaryEntries.Remove(entry); List <ViewModel_DiaryPage> entries = new List <ViewModel_DiaryPage>(DiaryEntries); UserDiaryFileController.Save(entries); } }
//Creates a new Entry in the Diary with the EDITING state private void CreateEntry() { //Creates a new entry if (DiaryEntries.Count <= 50) //Diary Cover counts as diary Entry { ViewModel_DiaryPage newEntry = new ViewModel_DiaryEntry() { Entry = new DiaryEntry() { FirstSubmit = DateTime.Now }, CurrentState = ViewModel_DiaryPage.PageState.EDITING }; DiaryEntries.Add(newEntry); NewDiaryEntryAdded(this, EventArgs.Empty); } else { EntryLimitReached(this, EventArgs.Empty); } }
private void EditEntry(ViewModel_DiaryEntry entry) { //Edits an entry Console.WriteLine(entry); //Triggered when the user clicks the EditEntry or NewEntry button if (entry.CurrentState == ViewModel_DiaryPage.PageState.COMPLETED) { //If it was a new frame, change the first submit field Console.WriteLine("Setting First Submit"); (entry.Entry).FirstSubmit = DateTime.Now; (entry.Entry).LastEdited = DateTime.Now; } //Finally, change the current entry to be EDIT state //entry.CurrentState = ViewModel_DiaryEntry.DiaryEntryState.EDITING; ViewModel_DiaryEntry updatedEntry = new ViewModel_DiaryEntry() { Entry = entry.Entry, CurrentState = ViewModel_DiaryPage.PageState.EDITING }; int i = DiaryEntries.IndexOf(entry); DiaryEntries[i] = updatedEntry; }
//Saves the Diary Entry public void SaveEntry(ViewModel_DiaryEntry entry) { //Saves an entry Console.WriteLine("Saving Entry " + entry.CurrentState); entry.Entry.LastEdited = DateTime.Now; AppPreferences.LastDiaryEntry = entry.Entry.LastEdited; ViewModel_DiaryEntry updatedEntry = new ViewModel_DiaryEntry() { Entry = entry.Entry }; updatedEntry.CurrentState = ViewModel_DiaryPage.PageState.COMPLETED; int i = DiaryEntries.IndexOf(entry); DiaryEntries[i] = updatedEntry; List <ViewModel_DiaryPage> entries = new List <ViewModel_DiaryPage>(DiaryEntries); //Adds current diary list from viewmodel UserDiaryFileController.Save(entries); }