public void OnEntryAddedOrUpdated(NoteEntryModel noteEntryModel, NoteOperationType noteOperationType)
        {
            if (noteOperationType == NoteOperationType.AddOrEdit)
            {
                var existingNote = Notes.FirstOrDefault(n => n.Id == noteEntryModel.Id);

                if (existingNote != null)
                {
                    Notes.Remove(existingNote);
                }

                Notes.Add(noteEntryModel);
            }

            else if (noteOperationType == NoteOperationType.Delete)
            {
                var existingNote = Notes.FirstOrDefault(n => n.Id == noteEntryModel.Id);

                if (existingNote != null)
                {
                    Notes.Remove(existingNote);
                }
            }

            _controller.TableView.ReloadData();
        }
Example #2
0
 public void UpdateCell(NoteEntryModel model)
 {
     if (model != null)
     {
         NoteTimeLabel.Text        = model.CreatedOn.ToString("dd/MM/yyyy");
         NoteTitleLabel.Text       = model.Title;
         NoteDesctiptionLabel.Text = model.Text == null ? string.Empty : model.Text.Length > 60 ? model.Text?.Substring(0, 60) : model.Text;
     }
 }
        public void SetDetailItem(NoteEntryModel note)
        {
            if (Note != note)
            {
                Note = note;

                // Update the view
                ConfigureView();
            }
        }
 private void SetNoteId(List <NoteEntryModel> notes, NoteEntryModel note)
 {
     if (notes.Any())
     {
         var maxNoteId = notes.Select(n => n.Id).Max();
         note.Id = ++maxNoteId;
     }
     else
     {
         note.Id = 1;
     }
 }
        public async Task <string> NoteExists(NoteEntryModel note)
        {
            if (note.Id > 0)
            {
                return(string.Empty);
            }

            var notes = await GetNotes();

            var noteExists = notes.Any(n => n.Title.Equals(note.Title, StringComparison.CurrentCultureIgnoreCase));

            return(noteExists ? "Note with same name already exists" : string.Empty);
        }
        public async Task <bool> RemoveNote(NoteEntryModel note)
        {
            var notes = await GetNotes();

            var noteToRemove = notes?.FirstOrDefault(n => n.Id == note.Id);

            if (noteToRemove == null)
            {
                return(false);
            }

            notes.Remove(noteToRemove);

            return(await SaveNotes(notes));
        }
        public async Task <bool> AddOrUpdateNote(NoteEntryModel note)
        {
            var notes = await GetNotes() ?? new List <NoteEntryModel>();

            if (note.Id == 0)
            {
                SetNoteId(notes, note);
            }
            else
            {
                var existingNote = notes.FirstOrDefault(n => n.Id == note.Id);
                if (existingNote != null)
                {
                    notes.Remove(existingNote);
                }
            }

            notes.Add(note);

            return(await SaveNotes(notes));
        }
Example #8
0
 public async Task <bool> RemoveEntry(NoteEntryModel entry)
 {
     return(await NoteStorageService.RemoveNote(entry));
 }
Example #9
0
 public async Task <bool> AddEntry(NoteEntryModel entry)
 {
     return(await NoteStorageService.AddOrUpdateNote(entry));
 }