public async Task <IActionResult> OnGetAsync(int?id)
        {
            UID  = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
            NAME = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name).Value;
            if (id == null)
            {
                return(NotFound());
            }
            IQueryable <Notes> AllNotes;

            AllNotes = from r in _context.Note
                       where r.RecordId == id
                       orderby r.AddTime descending
                       select r;

            Comments = await AllNotes.ToListAsync();

            Record = await _context.Record.FirstOrDefaultAsync(u => u.rid == id);

            foreach (var n in Comments)
            {
                Notes.Add($"{n.OperatorName} 评论:  {n.Content}     --{n.AddTime.ToString("MM-dd HH:mm")}");
            }

            return(Page());
        }
Пример #2
0
        public async Task <IActionResult> Index()
        {
            AllNotes = await _db.Notes.ToListAsync();

            AllNotes = AllNotes.OrderByDescending(n => n.Date_Created).ToList();
            return(View(AllNotes));
        }
        private void ShowNote(object value)
        {
            Guid          noteId = (value is Guid) ? (Guid)value : new Guid(value.ToString());
            NoteViewModel note   = AllNotes.FirstOrDefault(item => item.Id == noteId);

            if (note != null)
            {
                Navigation navigation = null;
                switch (note.Model.NoteType)
                {
                case NoteType.Text:
                    navigation = new Navigation(ControllerNames.Note, ControllerParameters.NoteId, noteId.ToString());
                    break;

                case NoteType.Checklist:
                    navigation = new Navigation(ControllerNames.Checklist, ControllerParameters.NoteId, noteId.ToString());
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(NoteType));
                }

                SettingsModel settings = _settingsService?.LoadSettingsOrDefault();
                if (!string.IsNullOrEmpty(settings.Filter))
                {
                    navigation.Variables.AddOrReplace(ControllerParameters.SearchFilter, settings.Filter);
                }
                _navigationService.Navigate(navigation);
            }
        }
Пример #4
0
        private static void initializeNotes()
        {
            string[]     fileNames = Directory.GetFiles(DirectoryName);
            StreamReader file;

            foreach (string name in fileNames)
            {
                file = new StreamReader(name);
                var note = new Note();
                fillNote(note, name);
                AllNotes.Add(note);
                file.Close();
            }

            void fillNote(Note note, string name)
            {
                string textLine;

                note.Categories    = takeCategories(file);
                note.Date          = takeDate(file);
                note.DateFormatted = note.Date.ToString("MM/dd/yyyy");
                note.Title         = name.Substring(name.LastIndexOf('\\') + 1, name.LastIndexOf('.') - name.LastIndexOf('\\') - 1);
                note.FileType      = name.Substring(name.LastIndexOf('.') + 1);
                note.IsMarkdown    = note.FileType != "txt";

                while ((textLine = file.ReadLine()) != null)
                {
                    note.Content += textLine;
                }
            }
        }
        public void FilterNotes()
        {
            if (_filter == null)
            {
                _filter = "";
            }

            // Changes search term to lowercase.
            var lowerCased = _filter.ToLowerInvariant().Trim();

            // Checks all note titles to see if the search term matches.
            var result = AllNotes.Where(n => n.Title.ToLowerInvariant()
                                        .Contains(lowerCased))
                         .ToList();

            // Remove all instances that do not match the search term.
            var remove = Notes.Except(result).ToList();

            foreach (var x in remove)
            {
                Notes.Remove(x);
            }

            // Adds values back in the correct order it was previously in.
            var resultCount = result.Count;

            for (int i = 0; i < resultCount; i++)
            {
                var resultItem = result[i];
                if (i + 1 > Notes.Count || !Notes[i].Equals(resultItem))
                {
                    Notes.Insert(i, resultItem);
                }
            }
        }
        private void DeleteNote(object value)
        {
            Guid          noteId       = (value is Guid) ? (Guid)value : new Guid(value.ToString());
            NoteViewModel selectedNote = AllNotes.Find(item => item.Id == noteId);

            if (selectedNote == null)
            {
                return;
            }
            Modified = true;

            // Mark note as deleted
            selectedNote.InRecyclingBin = true;

            // Remove note from filtered list
            int selectedIndex = FilteredNotes.IndexOf(selectedNote);

            FilteredNotes.RemoveAt(selectedIndex);

            Tags = Model.CollectActiveTags();
            Tags.Insert(0, EmptyTagFilter);
            OnPropertyChanged("Tags");

            // If the note was the last one containing the selected tag, the filter should be cleared
            if (!SelectedTagExistsInTags())
            {
                SelectedTag = null;
            }
            else
            {
                OnPropertyChanged("Notes");
            }

            _feedbackService.ShowToast(Language.LoadText("feedback_note_to_recycle"));
        }
        private void NewNote(NoteType noteType)
        {
            Modified = true;
            ClearFilter();

            // Create new note and update model list
            NoteModel noteModel = new NoteModel();

            noteModel.NoteType           = noteType;
            noteModel.BackgroundColorHex = _settingsService.LoadSettingsOrDefault().DefaultNoteColorHex;

            // Update view model list
            NoteViewModel     noteViewModel = new NoteViewModel(_navigationService, Language, Icon, Theme, _webviewBaseUrl, _searchableTextConverter, _repositoryService, _feedbackService, null, _noteCryptor, _model.Safes, _model.CollectActiveTags(), noteModel);
            NoteInsertionMode insertionMode = _settingsService.LoadSettingsOrDefault().DefaultNoteInsertion;

            switch (insertionMode)
            {
            case NoteInsertionMode.AtTop:
                var lastPinned = AllNotes.LastOrDefault(x => x.IsPinned == true);
                var index      = lastPinned == null ? 0 : AllNotes.IndexOf(lastPinned) + 1;
                _model.Notes.Insert(index, noteModel);
                AllNotes.Insert(index, noteViewModel);
                break;

            case NoteInsertionMode.AtBottom:
                _model.Notes.Add(noteModel);
                AllNotes.Add(noteViewModel);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(insertionMode));
            }

            ShowNoteCommand.Execute(noteViewModel.Id);
        }
Пример #8
0
 public MainPageViewModel()
 {
     EraseCommand = new Command(() => { TheNote = ""; });
     SaveCommand  = new Command(() =>
     {
         AllNotes.Add(TheNote);
         TheNote = "";
     });
 }
Пример #9
0
 public void SaveNewNote()
 {
     if (!String.IsNullOrEmpty(NewTextTitle))
     {
         AllNotes.Add(new Note(NewTextTitle, NewTextNote, DateTime.Now));
         _navigationService.GoBack();
         NewTextTitle = String.Empty;
         NewTextNote  = String.Empty;
     }
 }
Пример #10
0
 public void AddNote()
 {
     AllNotes.Add(new NoteModel()
     {
         InputTxt  = EditorInput,
         ImgSource = "https://picsum.photos/200/?random=" + new Random().Next().ToString()
     });
     ToNotesFile();
     EditorInput = "";
     NotifyPropertyChanged(EditorInput);
 }
Пример #11
0
 /// <summary>
 /// Update the notes when Notes event is triggered
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnDataServiceChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "Notes")
     {
         AllNotes.Clear();
         foreach (Note n in DataService.Instance.Notes)
         {
             AllNotes.Add(n);
         }
     }
 }
        public void RemoveNoteFromSafe(Guid noteId)
        {
            NoteViewModel note = AllNotes.Find(item => item.Id == noteId);

            if (note != null)
            {
                note.Model.SafeId      = null;
                note.Model.HtmlContent = note.UnlockedHtmlContent;
                note.Model.RefreshModifiedAt();
                Modified = true;
            }
        }
        public void AddNoteToSafe(Guid noteId)
        {
            NoteViewModel note           = AllNotes.Find(item => item.Id == noteId);
            SafeModel     oldestOpenSafe = Model.Safes.FindOldestOpenSafe();

            if ((note != null) && (oldestOpenSafe != null))
            {
                note.Model.SafeId      = oldestOpenSafe.Id;
                note.Model.HtmlContent = note.Lock(note.UnlockedHtmlContent);
                note.Model.RefreshModifiedAt();
                Modified = true;
            }
        }
Пример #14
0
 public void Refresh()
 {
     AllNotes.Clear();
     foreach (var n in _context.Notes)
     {
         AllNotes.Add(n);
     }
     Categories.Clear();
     foreach (var c in _context.NoteCategories)
     {
         Categories.Add(c);
     }
 }
Пример #15
0
        void dockManager_DockItemClosed(object sender, DockItemClosedEventArgs e)
        {
            DocumentPanel document = e.Item as DocumentPanel;

            if (document != null)
            {
                Note note = Note.GetNote(document);
                if (note != null && AllNotes.Remove(note))
                {
                    dockManager.DockController.RemovePanel(document);
                    Note.SetNote(document, null);
                }
            }
        }
Пример #16
0
        static void initializeNotes()
        {
            string[]     fileNames = Directory.GetFiles(DirectoryName);
            StreamReader file;
            Note         newNote;
            string       categoryHeader, dateHeader, textLine;
            int          day, month, year;

            foreach (string name in fileNames)
            {
                newNote = new Note();
                file    = new StreamReader(name);
                checkFormat();
                if (isFormatProper())
                {
                    fillNote(name);
                    AllNotes.Add(newNote);
                    file.Close();
                }
            }



            AllNotes = AllNotes.OrderBy(note => note.ValidityDate.Day).ToList();

            void checkFormat()
            {
                categoryHeader = file.ReadLine();
                dateHeader     = file.ReadLine();
            }

            bool isFormatProper() => categoryHeader.Substring(0, 9) == "category:" && dateHeader.Substring(0, 5) == "date:";

            void fillNote(string fileName)
            {
                year  = Int32.Parse(dateHeader.Substring(11));
                month = Int32.Parse(dateHeader.Substring(5, 2));
                day   = Int32.Parse(dateHeader.Substring(8, 2));
                newNote.ValidityDate = new DateTime(year, month, day);
                newNote.Category     = categoryHeader.Substring(9);
                newNote.Title        = fileName.Substring(fileName.LastIndexOf('/') + 1);
                newNote.Content      = "";
                while ((textLine = file.ReadLine()) != null)
                {
                    newNote.Content += textLine;
                }
            }
        }
Пример #17
0
        public MainPageViewModel()
        {
            EraseCommand = new Command(() => { TheNote = string.Empty; });
            SaveCommand  = new Command(() =>
            {
                AllNotes.Add(new Notes {
                    Note = TheNote
                });
                SavedNotes.Add(new Notes {
                    Note = TheNote
                });

                TheNote = string.Empty;
            });
            EraseNoteCommand = new Command(() => { AllNotes.Clear(); });
            UndoClearCommand = new Command(() => { AllNotes = SavedNotes; });
        }
        /// <summary>
        /// Command to move a note to a new place in the list. This is usually
        /// called after a drag and drop action.
        /// </summary>
        /// <param name="oldIndex">Index of the note to move.</param>
        /// <param name="newIndex">New index to place the note in.</param>
        public void MoveNote(int oldIndex, int newIndex)
        {
            if ((oldIndex == newIndex) ||
                !IsInRange(oldIndex, 0, FilteredNotes.Count - 1) ||
                !IsInRange(newIndex, 0, FilteredNotes.Count - 1))
            {
                return;
            }
            Modified = true;

            int oldIndexInUnfilteredList = AllNotes.IndexOf(FilteredNotes[oldIndex]);
            int newIndexInUnfilteredList = AllNotes.IndexOf(FilteredNotes[newIndex]);

            ListMove(_model.Notes, oldIndexInUnfilteredList, newIndexInUnfilteredList);
            ListMove(AllNotes, oldIndexInUnfilteredList, newIndexInUnfilteredList);
            FilteredNotes.Move(oldIndex, newIndex);
            _model.RefreshOrderModifiedAt();
        }
        public MainPageViewModel()
        {
            EraseCommand = new Command(() =>
            {
                TheNote = string.Empty;
            });

            // I think we really need too better grok the big arrow syntax because it's useful in all sorts of ways
            SaveCommand = new Command(() =>
            {
                AllNotes.Add(TheNote);

                System.Diagnostics.Debug.WriteLine("god save the queen");

                TheNote = string.Empty;
            });

            AllNotes = new ObservableCollection <string>();
        }
        public MainPageViewModel()
        {
            MessagingCenter.Subscribe <NoteDetailsViewModel>(this, "Unselect", (sender) =>
            {
                SelectedNote = null;
            });

            AddCommand = new Command(() =>
            {
                if (NewNote != "" && NewNote != null)
                {
                    NoteItem item = new NoteItem();

                    if (AllNotes.Count == 0)
                    {
                        item.Id = 1;
                    }
                    else
                    {
                        item.Id = AllNotes.LastOrDefault().Id + 1;
                    }

                    item.NoteText = NewNote;

                    AllNotes.Add(item);

                    AddToDB(item);

                    NewNote = string.Empty;
                }
            });

            SelectedNoteCommand = new Command(async() =>
            {
                if (SelectedNote != null)
                {
                    var noteDetailsVM              = new NoteDetailsViewModel(SelectedNote, AllNotes, ApiURL);
                    var noteDetailsPage            = new NoteDetails();
                    noteDetailsPage.BindingContext = noteDetailsVM;
                    await Application.Current.MainPage.Navigation.PushAsync(noteDetailsPage);
                }
            });
        }
Пример #21
0
        private void AddNote()
        {
            Modified = true;
            ClearFilter();

            // Create new note and update model list
            NoteModel noteModel = new NoteModel();

            noteModel.BackgroundColorHex = _settingsService.LoadSettingsOrDefault().DefaultNoteColorHex;
            _model.Notes.Insert(0, noteModel);

            // Update view model list
            NoteViewModel noteViewModel = new NoteViewModel(_navigationService, Language, Icon, _webviewBaseUrl, _searchableTextConverter, _repositoryService, null, noteModel);

            AllNotes.Insert(0, noteViewModel);
            FilteredNotes.Insert(0, noteViewModel);

            SelectedNote = noteViewModel;
            ShowNote(noteViewModel.Id);
        }
Пример #22
0
        private void DeleteNote(Guid noteId)
        {
            NoteViewModel selectedNote = AllNotes.Find(item => item.Id == noteId);

            if (selectedNote == null)
            {
                return;
            }
            Modified = true;

            // Mark note as deleted
            selectedNote.InRecyclingBin = true;

            // Remove note from filtered list
            int selectedIndex = FilteredNotes.IndexOf(selectedNote);

            FilteredNotes.RemoveAt(selectedIndex);
            OnPropertyChanged("Notes");

            _feedbackService.ShowToast(Language.LoadText("feedback_note_to_recycle"));
        }
Пример #23
0
        public MainPageViewModel()
        {
            SelectedNoteChangedCommand = new Command(async() =>
            {
                var detailVM              = new DetailPageViewModel(SelectedNote);
                var detailPage            = new DetailPage();
                detailPage.BindingContext = detailVM;

                await Application.Current.MainPage.Navigation.PushModalAsync(detailPage);
            });

            EraseCommand = new Command(() =>
            {
                TheNote = string.Empty;
            });

            SaveCommand = new Command(() =>
            {
                AllNotes.Add(TheNote);
                TheNote = string.Empty;
            });
        }
Пример #24
0
        DocumentPanel CreateNewNote()
        {
            Note note = new Note()
            {
                Caption = "Untitled", Book = ActiveBook
            };
            NotePage page = new NotePage()
            {
                Caption = "Untitled"
            };

            note.Pages.Add(page);
            DocumentPanel notePanel = CreateNoteDocument(note);
            bool          result    = dockManager.DockController.Insert(
                notesContainer, notePanel, notesContainer.Items.Count - 1
                );

            if (result)
            {
                AllNotes.Add(note);
            }
            return(result ? notePanel : null);
        }
Пример #25
0
        private void NewNote(NoteType noteType)
        {
            Modified = true;
            ClearFilter();

            // Create new note and update model list
            NoteModel noteModel = new NoteModel();

            noteModel.NoteType           = noteType;
            noteModel.HtmlContent        = "<h1> </h1>"; // Start with header format.
            noteModel.BackgroundColorHex = _settingsService.LoadSettingsOrDefault().DefaultNoteColorHex;

            // Update view model list
            NoteViewModel     noteViewModel = new NoteViewModel(_navigationService, Language, Icon, Theme, _webviewBaseUrl, _searchableTextConverter, _repositoryService, _feedbackService, null, _noteCryptor, _model.Safes, noteModel);
            NoteInsertionMode insertionMode = _settingsService.LoadSettingsOrDefault().DefaultNoteInsertion;

            switch (insertionMode)
            {
            case NoteInsertionMode.AtTop:
                _model.Notes.Insert(0, noteModel);
                AllNotes.Insert(0, noteViewModel);
                FilteredNotes.Insert(0, noteViewModel);
                break;

            case NoteInsertionMode.AtBottom:
                _model.Notes.Add(noteModel);
                AllNotes.Add(noteViewModel);
                FilteredNotes.Add(noteViewModel);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(insertionMode));
            }

            ShowNote(noteViewModel.Id);
        }
Пример #26
0
 /// <summary>
 /// Shows a list of all notes.
 /// </summary>
 /// <returns></returns>
 public ActionResult Index()
 {
     var notes = new AllNotes().Execute(_mongo);
     return View(notes);
 }
Пример #27
0
 public void DeleteNote(object sender)
 {
     AllNotes.Remove(sender as NoteModel);
     ToNotesFile();
 }
Пример #28
0
 public void Close()
 {
     AllNotes?.Close();
 }